Skip to content

Commit 2412f53

Browse files
committed
JS: Add steps and sinks for pipes
1 parent 23eeb49 commit 2412f53

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

javascript/ql/src/semmle/javascript/JsonStringifiers.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class JsonStringifyCall extends DataFlow::CallNode {
2525
callee = DataFlow::moduleMember("util", "inspect") or
2626
callee = DataFlow::moduleImport(["pretty-format", "object-inspect"])
2727
)
28+
or
29+
this = Templating::getAPipeCall(["json", "dump"])
2830
}
2931

3032
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,15 @@ module Templating {
531531
not file.getExtension() = any(TemplateSyntax s).getAFileExtension() and
532532
result = getTemplateSyntaxInFolder(file.getParentContainer())
533533
}
534+
535+
/** A step through the `safe` pipe, which bypasses HTML escaping. */
536+
private class SafePipeStep extends TaintTracking::SharedTaintStep {
537+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
538+
exists(DataFlow::CallNode call |
539+
call = getAPipeCall("safe") and
540+
pred = call.getArgument(0) and
541+
succ = call
542+
)
543+
}
544+
}
534545
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,16 @@ module DomBasedXss {
381381
}
382382
}
383383

384+
/**
385+
* A value being piped into the `safe` pipe in a template file,
386+
* disabling subsequent HTML escaping.
387+
*/
388+
class SafePipe extends DomBasedXss::Sink {
389+
SafePipe() {
390+
this = Templating::getAPipeCall("safe").getArgument(0)
391+
}
392+
}
393+
384394
/**
385395
* A property read from a safe property is considered a sanitizer.
386396
*/

0 commit comments

Comments
 (0)