Skip to content

Commit 0a26e89

Browse files
committed
include startsWith/endsWith checks in js/missing-origin-check
1 parent fe3d71e commit 0a26e89

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

javascript/ql/src/Security/CWE-020/MissingOriginCheck.ql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ predicate hasOriginCheck(PostMessageHandler handler) {
6666
or
6767
// set.includes(event.source)
6868
exists(InclusionTest test | sourceOrOrigin(handler).flowsTo(test.getContainedNode()))
69+
or
70+
// "safeOrigin".startsWith(event.origin)
71+
exists(StringOps::StartsWith starts |
72+
origin(DataFlow::TypeTracker::end(), handler).flowsTo(starts.getSubstring())
73+
)
74+
or
75+
// "safeOrigin".endsWith(event.origin)
76+
exists(StringOps::EndsWith ends |
77+
origin(DataFlow::TypeTracker::end(), handler).flowsTo(ends.getSubstring())
78+
)
6979
}
7080

7181
from PostMessageHandler handler

javascript/ql/test/query-tests/Security/CWE-020/MissingOriginCheck/tst.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ function is_valid_origin(origin) {
6161
warn("invalid origin: " + origin);
6262
}
6363
return valid;
64-
}
64+
}
65+
66+
window.onmessage = event => { // OK - the check is OK
67+
if ("https://www.example.com".startsWith(event.origin)) {
68+
// do something
69+
}
70+
}

0 commit comments

Comments
 (0)