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

feat(JS rules): add express rule against server side request forgery #636

Merged
merged 2 commits into from
Feb 22, 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
4 changes: 4 additions & 0 deletions integration/rules/javascript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func TestJavascriptExpressExposedDirListing(t *testing.T) {
getRunner(t).runTest(t, javascriptRulesPath+"express/exposed_dir_listing")
}

func TestJavascriptExpressServerSideRequestForgery(t *testing.T) {
getRunner(t).runTest(t, javascriptRulesPath+"express/server_side_request_forgery")
}

func TestExpressSecureCookie(t *testing.T) {
getRunner(t).runTest(t, javascriptRulesPath+"express/insecure_cookie")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
patterns:
- pattern: |
fetch($<EXPRESS_REQ>)
filters:
- variable: EXPRESS_REQ
detection: javascript_express_ssrf_request_obj
- pattern: |
axios.get($<EXPRESS_REQ>)
filters:
- variable: EXPRESS_REQ
detection: javascript_express_ssrf_request_obj
- pattern: |
$<PUPPETEER_PAGE>.$<METHOD>($<EXPRESS_REQ>)
filters:
- variable: PUPPETEER_PAGE
detection:
- variable: METHOD
values:
- goto
- setContent
- evaluate
- evaluateOnNewDocument
- variable: EXPRESS_REQ
detection: javascript_express_ssrf_request_obj
auxiliary:
- id: javascript_express_ssrf_request_obj
patterns:
- req.$<_>
- id: javascript_puppeteer_page
patterns:
- $<PUPPETEER_BROWSER>.newPage()
filters:
- variable: PUPPETEER_BROWSER
detection: javascript_puppeteer_browser
- id: javascript_puppeteer_browser
patterns:
- puppeteer.launch()
languages:
- javascript
trigger: presence
severity:
default: "medium"
metadata:
description: "Ensure server-side requests are sent to expected destination."
remediation_message: |
## Description
TODO.
cwe_id:
- 918
id: "javascript_express_server_side_request_forgery"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
medium:
- rule_dsrid: ""
rule_display_id: javascript_express_server_side_request_forgery
rule_description: Ensure server-side requests are sent to expected destination.
rule_documentation_url: https://docs.bearer.com/reference/rules/javascript_express_server_side_request_forgery
line_number: 7
filename: axios_ssrf_injection.js
parent_line_number: 7
parent_content: |-
axios
.get(req.query.path)


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
medium:
- rule_dsrid: ""
rule_display_id: javascript_express_server_side_request_forgery
rule_description: Ensure server-side requests are sent to expected destination.
rule_documentation_url: https://docs.bearer.com/reference/rules/javascript_express_server_side_request_forgery
line_number: 7
filename: node_fetch_ssrf_injection.js
parent_line_number: 7
parent_content: fetch("https://" + req.query.path)


Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{}


Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
medium:
- rule_dsrid: ""
rule_display_id: javascript_express_server_side_request_forgery
rule_description: Ensure server-side requests are sent to expected destination.
rule_documentation_url: https://docs.bearer.com/reference/rules/javascript_express_server_side_request_forgery
line_number: 11
filename: puppeteer_ssrf_injection.js
parent_line_number: 11
parent_content: page.setContent(content)
- rule_dsrid: ""
rule_display_id: javascript_express_server_side_request_forgery
rule_description: Ensure server-side requests are sent to expected destination.
rule_documentation_url: https://docs.bearer.com/reference/rules/javascript_express_server_side_request_forgery
line_number: 12
filename: puppeteer_ssrf_injection.js
parent_line_number: 12
parent_content: page.goto("https://"+req.query.path)


Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import express from "express";
import axios from 'axios';

const app = express()

app.get("/inject", async (req, res) => {
axios
.get(req.query.path)
.then(response => res.json(response.data))
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from "express";
import fetch from 'node-fetch';

const app = express()

app.get("/inject", async (req, res) => {
response = await fetch("https://" + req.query.path);
res.json(response.data);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import express from "express";
import puppeteer from "puppeteer";

const app = express()

app.get("/safety", async (_req, res) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://mish.bearer.com");

res.send("success")
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express from "express";
import puppeteer from "puppeteer";

const app = express()

app.get("/inject", async (req, res) => {
const browser = await puppeteer.launch();
const page = await browser.newPage();

var content = req.body.content
await page.setContent(content);
await page.goto("https://"+req.query.path);

res.send("success")
});