Skip to content

Commit 00d91dc

Browse files
committed
Created guide on customizing these queries, and referenced it in the query help
1 parent 040f948 commit 00d91dc

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Functionaility from untrusted source/domain - customizations
2+
3+
You can extend the behavior of the `js/functionality-from-untrusted-source` and `js/functionality-from-untrusted-domain` queries using [CodeQL data extensions](https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript/).
4+
5+
This allows you to require Subresource Integrity (SRI) checks on specific content delivery network (CDN) hostnames, and add additional domains to warn on, respectively.
6+
7+
For example, this YAML model can be used inside a CodeQL model pack to alert on uses of `example.com` in imported functionality, extending the `js/functionality-from-untrusted-domain` query:
8+
9+
```yaml
10+
extensions:
11+
- addsTo:
12+
pack: codeql/javascript-all
13+
extensible: untrustedDomain
14+
data:
15+
- ["example.com"]
16+
```
17+
18+
To add new hostnames that always require SRI checking, this YAML model can be used to require SRI on `cdn.example.com`, extending the `js/functionality-from-untrusted-source` query:
19+
20+
```yaml
21+
extensions:
22+
- addsTo:
23+
pack: codeql/javascript-all
24+
extensible: isCdnDomainWithCheckingRequired
25+
data:
26+
- ["cdn.example.com"]
27+
```
28+
29+
A suitable [model pack](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/creating-and-working-with-codeql-packs#creating-a-codeql-model-pack) might be:
30+
31+
```yaml
32+
name: my-org/javascript-untrusted-functionality-model-pack
33+
version: 1.0.0
34+
extensionTargets:
35+
codeql/java-all: '*'
36+
dataExtensions:
37+
- models/**/*.yml
38+
```
39+
40+
## References
41+
42+
- [Customizing library models for javascript](https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript/)
43+
- [Creating and working with CodeQL packs](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/creating-and-working-with-codeql-packs#creating-a-codeql-model-pack)

javascript/ql/src/Security/CWE-830/FunctionalityFromUntrustedDomain.qhelp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<p>
3333
Even when <code>https</code> is used, an untrustworthy operator might deliver malware.
3434
</p>
35+
36+
<p>
37+
See the `CUSTOMIZING.md` file in the source code for this query for information on how to extend the list of untrusted domains used by this query.
38+
</p>
3539
</overview>
3640

3741
<recommendation>

0 commit comments

Comments
 (0)