File tree Expand file tree Collapse file tree
javascript/ql/src/semmle/javascript/security/dataflow Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 */
66
77import javascript
8+ import Statements.UselessConditional
89
910module ExceptionXss {
1011 import DomBasedXssCustomizations:: DomBasedXss as DomBasedXssCustom
@@ -63,15 +64,24 @@ module ExceptionXss {
6364 NotYetThrown ( ) { this = "NotYetThrown" }
6465 }
6566
66- // Consider using "if (err) {.. [do something with err] .. }" as an extra condition if there are too many FP's.
67+ /**
68+ * A callback that is the last argument to some call, and the callback has the form:
69+ * function (err, value) {if (err) {...} .. }
70+ */
6771 class Callback extends DataFlow:: FunctionNode {
72+ DataFlow:: ParameterNode errorParameter ;
73+
6874 Callback ( ) {
6975 exists ( DataFlow:: CallNode call | call .getLastArgument ( ) .getAFunctionValue ( ) = this ) and
7076 this .getNumParameter ( ) = 2 and
71- this .getParameter ( 0 ) .getName ( ) .regexpMatch ( "err.*" ) // Using "e" was considered. But that matches too many jQuery methods where "element" is shortened as "e".
77+ errorParameter = this .getParameter ( 0 ) and
78+ exists ( Expr errorCheck |
79+ isExplicitConditional ( this .getFunction ( ) .getBodyStmt ( 0 ) , errorCheck ) and
80+ errorParameter .flowsTo ( DataFlow:: valueNode ( errorCheck ) )
81+ )
7282 }
7383
74- DataFlow:: Node getErrorParam ( ) { result = this . getParameter ( 0 ) }
84+ DataFlow:: Node getErrorParam ( ) { result = errorParameter }
7585 }
7686
7787 // `someFunction(.. <pred> .., (<result>, value) => {...}).
You can’t perform that action at this time.
0 commit comments