Skip to content

Commit

Permalink
New Published Rules - p0_security.direct-response-write-copy (#3382)
Browse files Browse the repository at this point in the history
* add p0_security/direct-response-write-copy.yaml

* add p0_security/direct-response-write-copy.jsx

* move direct-response-write rule to xss folder

* update direct-response-write metadata

---------

Co-authored-by: Nathan Brahms <nbrahms@gmail.com>
Co-authored-by: Vasilii <inkz@xakep.ru>
  • Loading branch information
3 people committed May 9, 2024
1 parent 48f6e91 commit 4c5bd64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ app.get('/xss', function (req, res) {
res.write('Response</br>' + html);
});

const jsonRouter = express.Router();
jsonRouter.use(express.json());
jsonRouter.get('/noxss-json', function (req, res) {
var name = req.query.name;
// ok: direct-response-write
res.write({ name });
});
app.use(jsonRouter);

// For https://github.com/returntocorp/semgrep-rules/issues/2872
app.post(
"/:id",
Expand Down
16 changes: 10 additions & 6 deletions javascript/express/security/audit/xss/direct-response-write.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
rules:
- id: direct-response-write
message: >-
Detected directly writing to a Response object from user-defined input. This bypasses
any HTML escaping and may expose your application to a Cross-Site-scripting
(XSS) vulnerability. Instead, use 'resp.render()' to render
safely escaped HTML.
Detected directly writing to a Response object from user-defined input.
This bypasses any HTML escaping and may expose your application to a Cross-Site-scripting
(XSS) vulnerability. Instead, use 'resp.render()' to render safely escaped HTML.
options:
interfile: true
metadata:
Expand All @@ -15,7 +14,8 @@ rules:
- A07:2017 - Cross-Site Scripting (XSS)
- A03:2021 - Injection
cwe:
- "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')"
- 'CWE-79: Improper Neutralization of Input During Web Page Generation (''Cross-site
Scripting'')'
category: security
technology:
- express
Expand All @@ -26,6 +26,9 @@ rules:
likelihood: MEDIUM
impact: MEDIUM
confidence: MEDIUM
license: Commons Clause License Condition v1.0[LGPL-2.1-only]
vulnerability_class:
- Cross-Site-Scripting (XSS)
languages:
- javascript
- typescript
Expand Down Expand Up @@ -112,6 +115,7 @@ rules:
- pattern: $RES.send($ARG)
- pattern-not: $RES. ... .set('...'). ... .send($ARG)
- pattern-not: $RES. ... .type('...'). ... .send($ARG)
- pattern-not-inside: $RES.$METHOD({ ... })
- focus-metavariable: $ARG
pattern-sanitizers:
- patterns:
Expand Down Expand Up @@ -222,7 +226,7 @@ rules:
- metavariable-regex:
metavariable: $F
regex: (?!.*text/html)
- patterns:
- patterns:
- pattern-inside: |
$X = [...];
...
Expand Down

0 comments on commit 4c5bd64

Please sign in to comment.