Skip to content

Commit 087c555

Browse files
authored
Merge pull request #18670 from asgerf/js/test-suite
JS: Update test suite to use post-processed inline expectations
2 parents a4f2264 + 6499e54 commit 087c555

File tree

1,106 files changed

+12915
-13112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,106 files changed

+12915
-13112
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ private module Postgres {
221221

222222
/** Gets a value that is plugged into a raw placeholder variable, making it a sink for SQL injection. */
223223
private DataFlow::Node getARawValue() {
224-
result = this.getValues() and this.getARawParameterName() = "1" // Special case: if the argument is not an array or object, it's just plugged into $1
224+
result = this.getValues() and
225+
this.getARawParameterName() = "1" and // Special case: if the argument is not an array or object, it's just plugged into $1
226+
not result instanceof DataFlow::ArrayCreationNode and
227+
not result instanceof DataFlow::ObjectLiteralNode
225228
or
226229
exists(DataFlow::SourceNode values | values = this.getValues().getALocalSource() |
227230
result = values.getAPropertyWrite(this.getARawParameterName()).getRhs()

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,22 @@ private module ClosureLibraryUri {
421421
}
422422
}
423423
}
424+
425+
private class QueryStringStringification extends DataFlow::SummarizedCallable {
426+
QueryStringStringification() { this = "query-string stringification" }
427+
428+
override DataFlow::InvokeNode getACall() {
429+
result =
430+
API::moduleImport(["querystring", "query-string", "querystringify", "qs"])
431+
.getMember("stringify")
432+
.getACall() or
433+
result = API::moduleImport("url-parse").getMember("qs").getMember("stringify").getACall() or
434+
result = API::moduleImport("parseqs").getMember("encode").getACall()
435+
}
436+
437+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
438+
preservesValue = false and
439+
input = ["Argument[0]", "Argument[0].AnyMemberDeep"] and
440+
output = "ReturnValue"
441+
}
442+
}

javascript/ql/lib/semmle/javascript/security/dataflow/ServerSideUrlRedirectQuery.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ module ServerSideUrlRedirectConfig implements DataFlow::ConfigSig {
2020

2121
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
2222

23-
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
23+
predicate isBarrier(DataFlow::Node node) {
24+
node instanceof Sanitizer
25+
or
26+
node = HostnameSanitizerGuard::getABarrierNode()
27+
}
2428

2529
predicate isBarrierOut(DataFlow::Node node) { hostnameSanitizingPrefixEdge(node, _) }
2630

@@ -69,10 +73,12 @@ deprecated class Configuration extends TaintTracking::Configuration {
6973
}
7074

7175
/**
76+
* DEPRECATED. This is no longer used as a sanitizer guard.
77+
*
7278
* A call to a function called `isLocalUrl` or similar, which is
7379
* considered to sanitize a variable for purposes of URL redirection.
7480
*/
75-
class LocalUrlSanitizingGuard extends DataFlow::CallNode {
81+
deprecated class LocalUrlSanitizingGuard extends DataFlow::CallNode {
7682
LocalUrlSanitizingGuard() { this.getCalleeName().regexpMatch("(?i)(is_?)?local_?url") }
7783

7884
/** DEPRECATED. Use `blocksExpr` instead. */

javascript/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ private import codeql.util.test.InlineExpectationsTest
44
module Impl implements InlineExpectationsTestSig {
55
private import javascript
66

7-
final private class LineCommentFinal = LineComment;
7+
final class ExpectationComment = ExpectationCommentImpl;
88

9-
class ExpectationComment extends LineCommentFinal {
10-
string getContents() { result = this.getText() }
9+
class Location = JS::Location;
10+
11+
abstract private class ExpectationCommentImpl extends Locatable {
12+
abstract string getContents();
1113

1214
/** Gets this element's location. */
1315
Location getLocation() { result = super.getLocation() }
1416
}
1517

16-
class Location = JS::Location;
18+
private class JSComment extends ExpectationCommentImpl instanceof Comment {
19+
override string getContents() { result = super.getText() }
20+
}
21+
22+
private class HtmlComment extends ExpectationCommentImpl instanceof HTML::CommentNode {
23+
override string getContents() { result = super.getText() }
24+
}
1725
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed a recently-introduced bug that caused `js/server-side-unvalidated-url-redirection` to ignore
5+
valid hostname checks and report spurious alerts after such a check. The original behaviour has been restored.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
AngularJS/DeadAngularJSEventListener.ql
1+
query: AngularJS/DeadAngularJSEventListener.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
angular.module('myModule', [])
22
.controller('MyController', function($scope) {
3-
$scope.$on('destroy', cleanup); // BAD
3+
$scope.$on('destroy', cleanup); // $ Alert
44
})
55
.controller('MyController', ["$scope", function(s) {
6-
s.$on('destroy', cleanup); // BAD
6+
s.$on('destroy', cleanup); // $ Alert
77
}])
88
.controller('MyController', function($scope) {
99
var destroy = 'destroy';
10-
$scope.$on(destroy, cleanup); // BAD
10+
$scope.$on(destroy, cleanup); // $ Alert
1111
})
1212
.controller('MyController', function($scope) {
13-
$scope.$on('$destroy', cleanup); // GOOD
13+
$scope.$on('$destroy', cleanup);
1414
})
1515
.controller('MyController', function($scope) {
1616
$scope.$emit('foo');
17-
$scope.$on('foo', cleanup); // GOOD
17+
$scope.$on('foo', cleanup);
1818
})
1919
.controller('MyController', function($scope) {
20-
$scope.$on('bar', cleanup); // BAD
20+
$scope.$on('bar', cleanup); // $ Alert
2121
})
2222
.controller('MyController', function($scope) {
23-
$scope.$on('$locationChangeStart', cleanup); // OK
23+
$scope.$on('$locationChangeStart', cleanup);
2424
})
2525
.controller('MyController', function($scope) {
26-
$scope.$on('lib1.foo', cleanup); // OK
26+
$scope.$on('lib1.foo', cleanup);
2727
})
2828
.controller('MyController', function($scope) {
29-
$scope.$on('lib2:foo', cleanup); // OK
29+
$scope.$on('lib2:foo', cleanup);
3030
})
3131
.controller('MyController', function($scope) {
32-
$scope.$on('onClick', cleanup); // OK
32+
$scope.$on('onClick', cleanup);
3333
})
3434
.controller('MyController', function($scope) {
3535
function f($scope){
3636
$scope.$emit('probablyFromUserCode1')
3737
}
38-
$scope.$on('probablyFromUserCode1', cleanup); // OK
38+
$scope.$on('probablyFromUserCode1', cleanup);
3939
})
4040
.controller('MyController', function($scope) {
4141
function f($scope){
4242
var scope = $scope;
4343
scope.$emit('probablyFromUserCode2')
4444
}
45-
$scope.$on('probablyFromUserCode2', cleanup); // OK
45+
$scope.$on('probablyFromUserCode2', cleanup);
4646
})
4747
.controller('MyController', function($scope) {
48-
$scope.$on('event-from-AngularJS-expression', cleanup); // GOOD
48+
$scope.$on('event-from-AngularJS-expression', cleanup);
4949
})
5050
;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
AngularJS/DependencyMismatch.ql
1+
query: AngularJS/DependencyMismatch.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
angular.module('app1', [])
2-
.run(['dep1', 'dep2', 'dep3', function(dep1, dep3, dep2) {}]); // NOT OK
2+
.run(['dep1', 'dep2', 'dep3', function(dep1, dep3, dep2) {}]); // $ Alert
33

44
angular.module('app2')
5-
.directive('mydirective', [ '$compile', function($compile, $http) { // NOT OK
5+
.directive('mydirective', [ '$compile', function($compile, $http) { // $ Alert
66
// ...
77
}]);
88

99
angular.module('app1', [])
10-
.run(['dep1', 'dep2', 'dep3', function(dep1, dep2, dep3) {}]); // OK
10+
.run(['dep1', 'dep2', 'dep3', function(dep1, dep2, dep3) {}]);
1111

1212
angular.module('app2')
13-
.directive('mydirective', [ '$compile', '$http', function($compile, $http) { // OK
13+
.directive('mydirective', [ '$compile', '$http', function($compile, $http) {
1414
// ...
1515
}]);
1616

1717
angular.module('app3', [])
18-
.run(function(dep1, dep3) {}); // OK
18+
.run(function(dep1, dep3) {});
1919

2020
angular.module('app4')
21-
.directive('mydirective', function($compile, $http) { // OK
21+
.directive('mydirective', function($compile, $http) {
2222
// ...
2323
});
2424

2525
angular.module('app5')
26-
.directive('mydirective', [ 'fully.qualified.name', function(name) { // OK
26+
.directive('mydirective', [ 'fully.qualified.name', function(name) {
2727
// ...
2828
}])
2929

3030
angular.module('app6')
3131
.directive('mydirective', function() {
3232
return {
33-
link: function (scope, element, attrs) { // OK
33+
link: function (scope, element, attrs) {
3434
}
3535
};
3636
});
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
angular.module('app', [])
22
.config(function($sceProvider) {
3-
$sceProvider.enabled(false); // BAD
3+
$sceProvider.enabled(false); // $ Alert
44
})
55
.config(['otherProvider', function($sceProvider) {
6-
$sceProvider.enabled(false); // OK
6+
$sceProvider.enabled(false);
77
}])
88
.config(['$sceProvider', function(x) {
9-
x.enabled(false); // BAD
9+
x.enabled(false); // $ Alert
1010
}])
1111
.config(function($sceProvider) {
12-
$sceProvider.enabled(true); // OK
12+
$sceProvider.enabled(true);
1313
})
1414
.config(function($sceProvider) {
1515
var x = false;
16-
$sceProvider.enabled(x); // BAD
16+
$sceProvider.enabled(x); // $ Alert
1717
});

0 commit comments

Comments
 (0)