File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
test/query-tests/Security/CWE-020/MissingOriginCheck Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,16 @@ predicate hasOriginCheck(PostMessageHandler handler) {
66
66
or
67
67
// set.includes(event.source)
68
68
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
+ )
69
79
}
70
80
71
81
from PostMessageHandler handler
Original file line number Diff line number Diff line change @@ -61,4 +61,10 @@ function is_valid_origin(origin) {
61
61
warn ( "invalid origin: " + origin ) ;
62
62
}
63
63
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
+ }
You can’t perform that action at this time.
0 commit comments