Skip to content

Commit 1474c07

Browse files
committed
JS: Introduce TemplateInstantiation
1 parent 8fe2d84 commit 1474c07

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

javascript/ql/src/semmle/javascript/frameworks/Express.qll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,4 +972,29 @@ module Express {
972972
.getParameter(0)
973973
}
974974
}
975+
976+
/**
977+
* A call to the Express `res.render()` method, seen as a template instantiation.
978+
*/
979+
private class RenderCallAsTemplateInstantiation extends Templating::TemplateInstantiaton::Range, DataFlow::CallNode {
980+
RenderCallAsTemplateInstantiation() {
981+
this = any(ResponseSource res).ref().getAMethodCall("render")
982+
}
983+
984+
override DataFlow::Node getTemplateFileNode() {
985+
result = getArgument(0)
986+
}
987+
988+
override DataFlow::Node getTemplateContentNode() {
989+
none()
990+
}
991+
992+
override DataFlow::Node getTemplateParamsNode() {
993+
result = getArgument(1)
994+
}
995+
996+
override DataFlow::SourceNode getOutput() {
997+
result = getCallback(2).getParameter(1)
998+
}
999+
}
9751000
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,42 @@ module Templating {
117117
result = getScope().getVariable(name).getAnAccess().flow()
118118
}
119119
}
120+
121+
/**
122+
* A place where a template is instantiated or rendered.
123+
*/
124+
class TemplateInstantiaton extends DataFlow::Node {
125+
TemplateInstantiaton::Range range;
126+
127+
TemplateInstantiaton() { this = range }
128+
129+
/** Gets a data flow node that refers to the instantiated template string, if any. */
130+
DataFlow::SourceNode getOutput() { result = range.getOutput() }
131+
132+
/** Gets a data flow node that refers a template file to be instantiated, if any. */
133+
DataFlow::Node getTemplateFileNode() { result = range.getTemplateFileNode() }
134+
135+
/** Gets a data flow node that refers to the contents of the template to be instantiated, if any. */
136+
DataFlow::Node getTemplateContentNode() { result = range.getTemplateContentNode() }
137+
138+
/** Gets a data flow node that refers to an object whose properties become variables in the template. */
139+
DataFlow::Node getTemplateParamsNode() { result = range.getTemplateParamsNode() }
140+
}
141+
142+
/** Companion module to the `TemplateInstantiation` class. */
143+
module TemplateInstantiaton {
144+
abstract class Range extends DataFlow::Node {
145+
/** Gets a data flow node that refers to the instantiated template, if any. */
146+
abstract DataFlow::SourceNode getOutput();
147+
148+
/** Gets a data flow node that refers a template file to be instantiated, if any. */
149+
abstract DataFlow::Node getTemplateFileNode();
150+
151+
/** Gets a data flow node that refers to the contents of the template to be instantiated, if any. */
152+
abstract DataFlow::Node getTemplateContentNode();
153+
154+
/** Gets a data flow node that refers to an object whose properties become variables in the template. */
155+
abstract DataFlow::Node getTemplateParamsNode();
156+
}
157+
}
120158
}

0 commit comments

Comments
 (0)