Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #11: Support double quotes in strings #12

Merged
merged 5 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/filtrex.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ function filtrexParser() {
return "SYMBOL";`
], // 'some-symbol'

['"(?:[^"])*"',
`yytext = JSON.stringify(
yytext.substr(1, yyleng-2)
);
return "STRING";`
], // "foo"
['"(?:\\\\"|[^"])*"', 'return "STRING";'], // "foo"
Copy link
Owner

@cshaa cshaa Aug 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your regex also matches "a\" as a legit string. The not-char pattern should be something like [^"\\] instead of [^"]. This can be used as an exploit, because the next string would be actually executed as JavaScript:

"a\" == "; window.p0wned = true; //"

Also, can you guarantee that removing the JSON.stringify won't result in any malicious code? We know that everything that comes out of stringify is safe. But how can we be sure every match of your regex is safe? (After fixing the previous bug, of course, now it obviously isn't safe.)


// End
['$', 'return "EOF";'],
Expand Down
11 changes: 8 additions & 3 deletions test/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ describe('Security', () => {
});


it('does backslash escaping', () =>
expect( compileExpression(`"\\" + '\\'`)({'\\':'good'}) ).equals('\\good')
);
it('does backslash escaping', () => {
expect( compileExpression(`"\\\\" + '\\'`)({'\\':'good'}) ).equals('\\good');
expect( compileExpression(`"\\\\" + '\\\\'`)({'\\\\':'good'}) ).equals('\\good');
});


it('in() is not vulnerable to Object.prototype extensions ', () => {
Expand All @@ -76,4 +77,8 @@ describe('Security', () => {
).equals(undefined);
})


it('supports double quotes inside strings', () => {
expect( compileExpression('"\\"test\\""')({}) ).equals('"test"');
});
});