Skip to content

Commit 1fe14e2

Browse files
committed
Split out "compromised" functionality
1 parent e2b37f9 commit 1fe14e2

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

javascript/ql/lib/semmle/javascript/security/FunctionalityFromUntrustedSource.qll

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,19 @@ module StaticCreation {
4242
"code\\.jquery\\.com", //
4343
"cdnjs\\.cloudflare\\.com", //
4444
"cdnjs\\.com", //
45-
"cdn\\.polyfill\\.io", // compromised
46-
"polyfill\\.io", // compromised
4745
] + "/.*\\.js$")
4846
}
4947

48+
/** Holds if `url` refers to a compromised CDN, that should not be trusted. */
49+
bindingset[url]
50+
predicate isCompromisedCdn(string url) {
51+
url.regexpMatch("(?i)^https?://" +
52+
[
53+
"cdn\\.polyfill\\.io", // See https://sansec.io/research/polyfill-supply-chain-attack for details
54+
"polyfill\\.io", // "
55+
] + "/.*$")
56+
}
57+
5058
/** A script element that refers to untrusted content. */
5159
class ScriptElementWithUntrustedContent extends AddsUntrustedUrl instanceof HTML::ScriptElement {
5260
ScriptElementWithUntrustedContent() {
@@ -59,6 +67,19 @@ module StaticCreation {
5967
override string getProblem() { result = "Script loaded using unencrypted connection." }
6068
}
6169

70+
/** A script element that refers to compromised content. */
71+
class CdnFromCompromisedSource extends AddsUntrustedUrl, HTML::ScriptElement {
72+
CdnFromCompromisedSource() {
73+
isCompromisedCdn(this.getSourcePath())
74+
}
75+
76+
override string getUrl() { result = this.getSourcePath() }
77+
78+
override string getProblem() {
79+
result = "Script loaded from compromised content delivery network."
80+
}
81+
}
82+
6283
/** A script element that refers to untrusted content. */
6384
class CdnScriptElementWithUntrustedContent extends AddsUntrustedUrl, HTML::ScriptElement {
6485
CdnScriptElementWithUntrustedContent() {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
22
category: minorAnalysis
33
---
4-
* Added a new query, `js/polyfill-io-compromised-script`, which detects uses in HTML and JavaScript of the compromised `polyfill.io` content delivery network.
4+
* Added a new query, `js/polyfill-io-compromised-script`, which detects uses in HTML and JavaScript of the compromised `polyfill.io` content delivery network.
5+
* Modified existing query, `js/functionality-from-untrusted-source`, to add a new check for the compromised `polyfill.io` content delivery network.
6+
* Created a shared library, `semmle.javascript.security.FunctionalityFromUntrustedSource`, to separate the logic from the existing query and allow having a separate new Polyfill-specific query.

0 commit comments

Comments
 (0)