Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0d5557

Browse files
committed
JS: add email HTML body as XSS sink
1 parent 48634d4 commit e0d5557

4 files changed

Lines changed: 42 additions & 4 deletions

File tree

javascript/ql/src/Security/CWE-079/Xss.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import javascript
1515
import semmle.javascript.security.dataflow.DomBasedXss::DomBasedXss
1616

17-
from Configuration xss, DataFlow::Node source, DataFlow::Node sink
17+
from Configuration xss, DataFlow::Node source, Sink sink
1818
where xss.hasFlow(source, sink)
19-
select sink, "Cross-site scripting vulnerability due to $@.",
20-
source, "user-provided value"
19+
select sink, sink.getVulnerabilityKind() + " vulnerability due to $@.",
20+
source, "user-provided value"

javascript/ql/src/semmle/javascript/security/dataflow/DomBasedXss.qll

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ module DomBasedXss {
1616
/**
1717
* A data flow sink for XSS vulnerabilities.
1818
*/
19-
abstract class Sink extends DataFlow::Node { }
19+
abstract class Sink extends DataFlow::Node {
20+
/**
21+
* Gets the kind of vulnerability to report in the alert message.
22+
*
23+
* Defaults to `Cross-site scripting`, but may be overriden for sinks
24+
* that do not allow script injection, but injection of other undesirable HTML elements.
25+
*/
26+
string getVulnerabilityKind() {
27+
result = "Cross-site scripting"
28+
}
29+
}
2030

2131
/**
2232
* A sanitizer for XSS vulnerabilities.
@@ -164,6 +174,18 @@ module DomBasedXss {
164174
}
165175
}
166176

177+
/**
178+
* The HTML body of an email, viewed as an XSS sink.
179+
*/
180+
class EmailHtmlBodySink extends Sink {
181+
EmailHtmlBodySink() {
182+
this = any(EmailSender sender).getHtmlBody()
183+
}
184+
185+
override string getVulnerabilityKind() {
186+
result = "HTML injection"
187+
}
188+
}
167189
}
168190

169191
/** DEPRECATED: Use `DomBasedXss::Source` instead. */

javascript/ql/test/query-tests/Security/CWE-079/Xss.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
| jquery.js:4:5:4:11 | tainted | Cross-site scripting vulnerability due to $@. | jquery.js:2:17:2:33 | document.location | user-provided value |
33
| jquery.js:7:5:7:34 | "<div i ... + "\\">" | Cross-site scripting vulnerability due to $@. | jquery.js:2:17:2:33 | document.location | user-provided value |
44
| jquery.js:8:18:8:34 | "XSS: " + tainted | Cross-site scripting vulnerability due to $@. | jquery.js:2:17:2:33 | document.location | user-provided value |
5+
| nodemailer.js:13:11:13:69 | `Hi, yo ... sage}.` | HTML injection vulnerability due to $@. | nodemailer.js:13:50:13:66 | req.query.message | user-provided value |
56
| react-native.js:8:18:8:24 | tainted | Cross-site scripting vulnerability due to $@. | react-native.js:7:17:7:33 | req.param("code") | user-provided value |
67
| react-native.js:9:27:9:33 | tainted | Cross-site scripting vulnerability due to $@. | react-native.js:7:17:7:33 | req.param("code") | user-provided value |
78
| string-manipulations.js:3:16:3:32 | document.location | Cross-site scripting vulnerability due to $@. | string-manipulations.js:3:16:3:32 | document.location | user-provided value |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let nodemailer = require('nodemailer');
2+
let express = require('express');
3+
let app = express();
4+
let backend = require('./backend');
5+
6+
app.post('/private_message', (req, res) => {
7+
let transport = nodemailer.createTransport({});
8+
transport.sendMail({
9+
10+
to: backend.getUserEmail(req.query.receiver),
11+
subject: 'Private message',
12+
text: `Hi, you got a message from someone. ${req.query.message}.`, // OK
13+
html: `Hi, you got a message from someone. ${req.query.message}.`, // NOT OK
14+
});
15+
});

0 commit comments

Comments
 (0)