Skip to content

Commit f1f3d8e

Browse files
jorgectfKwstubbs
andcommitted
Add dot.jssupport
Co-authored-by: Kevin Stubbings <[email protected]>
1 parent f8b1dc9 commit f1f3d8e

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static int skipBOM(byte[] bytes, int length) {
103103

104104
/** Information about supported file types. */
105105
public static enum FileType {
106-
HTML(".htm", ".html", ".xhtm", ".xhtml", ".vue", ".hbs", ".ejs", ".njk", ".erb") {
106+
HTML(".htm", ".html", ".xhtm", ".xhtml", ".vue", ".hbs", ".ejs", ".njk", ".erb", ".dot") {
107107
@Override
108108
public IExtractor mkExtractor(ExtractorConfig config, ExtractorState state) {
109109
return new HTMLExtractor(config, state);

javascript/ql/lib/semmle/javascript/frameworks/Templating.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,22 @@ module Templating {
580580
override string getAPackageName() { result = "ejs" }
581581
}
582582

583+
/**
584+
* doT-style syntax, using `{{! }}` for safe interpolation, and `{{= }}` for
585+
* unsafe interpolation.
586+
*/
587+
private class DotStyleSyntax extends TemplateSyntax {
588+
DotStyleSyntax() { this = "dot" }
589+
590+
override string getRawInterpolationRegexp() { result = "(?s)\\{\\{!(.*?)\\}\\}" }
591+
592+
override string getEscapingInterpolationRegexp() { result = "(?s)\\{\\{=(.*?)\\}\\}" }
593+
594+
override string getAFileExtension() { result = "dot" }
595+
596+
override string getAPackageName() { result = "dot" }
597+
}
598+
583599
private TemplateSyntax getOwnTemplateSyntaxInFolder(Folder f) {
584600
exists(PackageDependencies deps |
585601
deps.getADependency(result.getAPackageName(), _) and

javascript/ql/test/library-tests/frameworks/Templating/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ app.get('/angularjs', (req, res) => {
6666
rawHtml: req.query.rawHtml,
6767
});
6868
});
69+
70+
app.get('/dotjs', (req, res) => {
71+
res.render('dot_sinks', {
72+
tainted: req.query.foo,
73+
});
74+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
{{! tainted }}
4+
{{= tainted }}
5+
</body>
6+
</html>

0 commit comments

Comments
 (0)