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: open redirect js rules #315

Merged
merged 1 commit into from
Feb 23, 2024
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
22 changes: 21 additions & 1 deletion rules/javascript/express/open_redirect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@ imports:
- javascript_shared_common_user_input
patterns:
- pattern: |
res.redirect($<USER_INPUT>$<...>)
$<RES>.redirect($<USER_INPUT>$<...>)
filters:
- variable: RES
detection: javascript_express_open_redirect_response
- variable: USER_INPUT
detection: javascript_shared_common_user_input
scope: result
auxiliary:
- id: javascript_express_open_redirect_response
patterns:
- res
- response
# typescript
- |
const $<_>: Response = $<!>$<_>
- |
($<...>$<!>$<_>: Response$<...>) => {}
- |
($<...>$<!>$<_>: Response$<...>) {}
- |
function ($<...>$<!>$<_>: Response$<...>) {}
- |
function $<_>($<...>$<!>$<_>: Response$<...>) {}
- |
class $<_> $<...>{ $<...>$<_>($<...>$<!>$<_>: Response$<...>) {} }
languages:
- javascript
severity: medium
Expand Down
6 changes: 6 additions & 0 deletions rules/javascript/hapi/open_redirect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ patterns:
- pattern: |
$<RES>.redirect($<USER_INPUT>$<...>)
filters:
- not:
# avoid overlap with express js rule
variable: RES
values:
- res
- response
- variable: RES
detection: javascript_hapi_open_redirect_response_toolkit
- variable: USER_INPUT
Expand Down
1 change: 1 addition & 0 deletions rules/javascript/shared/express/user_input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ auxiliary:
- id: javascript_shared_express_user_input_request
patterns:
- req
- request
# typescript
- |
const $<_>: Request = $<!>$<_>
Expand Down
8 changes: 4 additions & 4 deletions tests/javascript/hapi/open_redirect/testdata/app.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Request, ResponseToolkit } from "@hapi/hapi";
import { Server, Request, ResponseToolkit } from "@hapi/hapi";
import { format as formatUrl } from 'url';

export class Foo {
public async bad(req: Request, res: ResponseToolkit) {
public async bad(request: Request, responseToolkit: ResponseToolkit) {
// bearer:expected javascript_hapi_open_redirect
return res
return responseToolkit
.redirect(formatUrl({
pathname: req.url.pathname
pathname: request.url.pathname
})
)
.takeover();
Expand Down
Loading