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 slow pattern and regex #3135

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 22 additions & 20 deletions typescript/lang/security/audit/cors-regex-wildcard.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
// ruleid: cors-regex-wildcard
const corsDomains = [
/localhost\:/,
/(.+\.)*foo\.com$/,
/(.+\.)*foobar\.com$/, // matches *.foobar.com,
/^(http|https):\/\/(qix|qux).biz.baz.foobar.com$/,
/^(http|https):\/\/www\.bar\.com$/,
/^(http|https):\/\/www.foo.com$/,
/localhost\:/,
/(.+\.)*foo\.com$/,
/(.+\.)*foobar\.com$/, // matches *.foobar.com,
// ruleid: cors-regex-wildcard
/^(http|https):\/\/(qix|qux).biz.baz.foobar.com$/,
/^(http|https):\/\/www\.bar\.com$/,
// ruleid: cors-regex-wildcard
/^(http|https):\/\/www.foo.com$/,
];

// ruleid: cors-regex-wildcard
const CORS = [
/localhost\:/,
/(.+\.)*foo\.com$/,
/(.+\.)*foobar\.com$/, // matches *.foobar.com,
/^(http|https):\/\/(qix|qux).biz.baz.foobar.com$/,
/^(http|https):\/\/www\.bar\.com$/,
/^(http|https):\/\/www.foo.com$/,
/localhost\:/,
/(.+\.)*foo\.com$/,
/(.+\.)*foobar\.com$/, // matches *.foobar.com,
// ruleid: cors-regex-wildcard
/^(http|https):\/\/(qix|qux).biz.baz.foobar.com$/,
/^(http|https):\/\/www\.bar\.com$/,
// ruleid: cors-regex-wildcard
/^(http|https):\/\/www.foo.com$/,
];

// ruleid: cors-regex-wildcard
const corsOrigin = /^(http|https):\/\/www.foo.com$/;

const urls = [
/localhost\:/,
/(.+\.)*foo\.com$/,
/(.+\.)*foobar\.com$/, // matches *.foobar.com,
/^(http|https):\/\/(qix|qux).biz.baz.foobar.com$/,
/^(http|https):\/\/www\.bar\.com$/,
/^(http|https):\/\/www.foo.com$/,
/localhost\:/,
/(.+\.)*foo\.com$/,
/(.+\.)*foobar\.com$/, // matches *.foobar.com,
/^(http|https):\/\/(qix|qux).biz.baz.foobar.com$/,
/^(http|https):\/\/www\.bar\.com$/,
/^(http|https):\/\/www.foo.com$/,
];
5 changes: 3 additions & 2 deletions typescript/lang/security/audit/cors-regex-wildcard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ rules:
severity: WARNING
patterns:
- pattern-either:
- pattern: const $CORS = [...,$PATTERN,...]
- pattern: const $CORS = $PATTERN
- pattern: $CORS = [...,/$PATTERN/,...]
- pattern: $CORS = /$PATTERN/
- focus-metavariable: $PATTERN
- metavariable-regex:
metavariable: $PATTERN
regex: .+?(?<!\\).\..+(?<!\\)\..+
Expand Down
Loading