You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9e6d428
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/customizing-library-models-for-actions.rst
+56-20Lines changed: 56 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,29 @@ Customizing library models for GitHub Actions
7
7
8
8
GitHub Actions analysis can be customized by adding library models in data extension files.
9
9
10
-
A data extension for GitHub Actions is a YAML file of the form:
10
+
A data extension for GitHub Actions can be written using either JSON or YAML. JSON is the preferred format, for performance reasons, and takes the following form:
11
+
12
+
.. code-block:: json
13
+
14
+
{
15
+
"extensions": [
16
+
{
17
+
"addsTo": {
18
+
"pack": "codeql/actions-all",
19
+
"extensible": "<name of extensible predicate>"
20
+
},
21
+
"data": [
22
+
["<value for row 1, column 1>", "<value for row 1, column 2>", "..."],
23
+
["<value for row 2, column 1>", "<value for row 2, column 2>", "..."]
24
+
// ...
25
+
]
26
+
}
27
+
]
28
+
}
29
+
30
+
Files in the JSON format must use the ``.json`` file extension. Single-line (``//``) and multi-line (``/* ... */``) comments are supported as a non-standard JSON extension.
31
+
32
+
A YAML file has the following form:
11
33
12
34
.. code-block:: yaml
13
35
@@ -16,8 +38,8 @@ A data extension for GitHub Actions is a YAML file of the form:
16
38
pack: codeql/actions-all
17
39
extensible: <name of extensible predicate>
18
40
data:
19
-
- <tuple1>
20
-
- <tuple2>
41
+
- ["<value for row 1, column 1>", "<value for row 1, column 2>", "..."]
42
+
- ["<value for row 2, column 1>", "<value for row 2, column 2>", "..."]
21
43
- ...
22
44
23
45
The CodeQL library for GitHub Actions exposes the following extensible predicates:
@@ -57,16 +79,23 @@ If there is an Action publisher that you trust, you can include the owner name/o
57
79
58
80
To allow any Action from the publisher ``octodemo``, such as ``octodemo/3rd-party-action``, follow these steps:
59
81
60
-
1. Create a data extension file ``/models/trusted-owner.model.yml`` with the following content:
82
+
1. Create a data extension file ``/models/trusted-owner.model.json`` with the following content:
61
83
62
-
.. code-block:: yaml
84
+
.. code-block:: json
63
85
64
-
extensions:
65
-
- addsTo:
66
-
pack: codeql/actions-all
67
-
extensible: trustedActionsOwnerDataModel
68
-
data:
69
-
- ["octodemo"]
86
+
{
87
+
"extensions": [
88
+
{
89
+
"addsTo": {
90
+
"pack": "codeql/actions-all",
91
+
"extensible": "trustedActionsOwnerDataModel"
92
+
},
93
+
"data": [
94
+
["octodemo"]
95
+
]
96
+
}
97
+
]
98
+
}
70
99
71
100
2. Create a model pack file ``/codeql-pack.yml`` with the following content:
72
101
@@ -78,7 +107,7 @@ To allow any Action from the publisher ``octodemo``, such as ``octodemo/3rd-part
78
107
extensionTargets:
79
108
codeql/actions-all: '*'
80
109
dataExtensions:
81
-
- models/**/*.yml
110
+
- models/**/*.json
82
111
83
112
3. Ensure that the model pack is included in your CodeQL analysis.
84
113
@@ -91,14 +120,21 @@ GitHub's own organizations (``actions``, ``github`` and ``advanced-security``) a
91
120
92
121
To distrust the first-party ``github`` owner, add a data extension file with the following content:
93
122
94
-
.. code-block:: yaml
95
-
96
-
extensions:
97
-
- addsTo:
98
-
pack: codeql/actions-all
99
-
extensible: trustedActionsOwnerDataModel
100
-
data:
101
-
- ["!github"]
123
+
.. code-block:: json
124
+
125
+
{
126
+
"extensions": [
127
+
{
128
+
"addsTo": {
129
+
"pack": "codeql/actions-all",
130
+
"extensible": "trustedActionsOwnerDataModel"
131
+
},
132
+
"data": [
133
+
["!github"]
134
+
]
135
+
}
136
+
]
137
+
}
102
138
103
139
With this in place, the query will once again report unpinned tags for Actions published by ``github``.
Each model of an element is defined using a data extension where each tuple constitutes a model.
28
-
A data extension file to extend the standard CPP queries included with CodeQL is a YAML file with the form:
28
+
A data extension file to extend the standard CPP queries included with CodeQL can be written using either JSON or YAML. JSON is the preferred format, for performance reasons, and takes the following form:
29
+
30
+
.. code-block:: json
31
+
32
+
{
33
+
"extensions": [
34
+
{
35
+
"addsTo": {
36
+
"pack": "codeql/cpp-all",
37
+
"extensible": "<name of extensible predicate>"
38
+
},
39
+
"data": [
40
+
["<value for row 1, column 1>", "<value for row 1, column 2>", "..."],
41
+
["<value for row 2, column 1>", "<value for row 2, column 2>", "..."]
42
+
// ...
43
+
]
44
+
}
45
+
]
46
+
}
47
+
48
+
Files in the JSON format must use the ``.json`` file extension. Single-line (``//``) and multi-line (``/* ... */``) comments are supported as a non-standard JSON extension.
49
+
50
+
A YAML file has the following form:
29
51
30
52
.. code-block:: yaml
31
53
@@ -34,11 +56,11 @@ A data extension file to extend the standard CPP queries included with CodeQL is
34
56
pack: codeql/cpp-all
35
57
extensible: <name of extensible predicate>
36
58
data:
37
-
- <tuple1>
38
-
- <tuple2>
59
+
- ["<value for row 1, column 1>", "<value for row 1, column 2>", "..."]
60
+
- ["<value for row 2, column 1>", "<value for row 2, column 2>", "..."]
39
61
- ...
40
62
41
-
Each YAML file may contain one or more top-level extensions.
63
+
Each data extension file may contain one or more top-level extensions.
42
64
43
65
- ``addsTo`` defines the CodeQL pack name and extensible predicate that the extension is injected into.
44
66
- ``data`` defines one or more rows of tuples that are injected as values into the extensible predicate. The number of columns and their types must match the definition of the extensible predicate.
@@ -79,20 +101,27 @@ This example shows how the CPP query pack models the return value from the ``rea
79
101
80
102
We need to add a tuple to the ``sourceModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance)`` extensible predicate by updating a data extension file.
The first five values identify the callable (in this case a free function) to be modeled as a source.
92
121
93
122
- The first value ``"boost::asio"`` is the namespace name.
94
123
- The second value ``""`` is the name of the type (class) that contains the method. Because we're modeling a free function, the type is left blank.
95
-
- The third value ``False`` is a flag that indicates whether or not the model also applies to all overrides of the method. For a free function, this should be ``False``.
124
+
- The third value ``false`` is a flag that indicates whether or not the model also applies to all overrides of the method. For a free function, this should be ``false``.
96
125
- The fourth value ``"read_until"`` is the function name.
97
126
- The fifth value is the function input type signature, which can be used to narrow down between functions that have the same name. In this case, we want the model to include all functions in ``boost::asio`` called ``read_until``.
98
127
@@ -114,20 +143,27 @@ This example shows how the CPP query pack models the second argument of the ``bo
114
143
115
144
We need to add a tuple to the ``sinkModel(namespace, type, subtypes, name, signature, ext, input, kind, provenance)`` extensible predicate by updating a data extension file.
The first five values identify the callable (in this case a free function) to be modeled as a sink.
127
163
128
164
- The first value ``"boost::asio"`` is the namespace name.
129
165
- The second value ``""`` is the name of the type (class) that contains the method. Because we're modeling a free function, the type is left blank.
130
-
- The third value ``False`` is a flag that indicates whether or not the model also applies to all overrides of the method. For a free function, this should be ``False``.
166
+
- The third value ``false`` is a flag that indicates whether or not the model also applies to all overrides of the method. For a free function, this should be ``false``.
131
167
- The fourth value ``"write"`` is the function name.
132
168
- The fifth value is the function input type signature, which can be used to narrow down between functions that have the same name. In this case, we want the model to include all functions in ``boost::asio`` called ``write``.
133
169
@@ -149,20 +185,27 @@ This example shows how the CPP query pack models flow through a function for a s
149
185
150
186
We need to add tuples to the ``summaryModel(namespace, type, subtypes, name, signature, ext, input, output, kind, provenance)`` extensible predicate by updating a data extension file:
The first five values identify the callable (in this case free function) to be modeled as a summary.
162
205
163
206
- The first value ``"boost::asio"`` is the namespace name.
164
207
- The second value ``""`` is the name of the type (class) that contains the method. Because we're modeling a free function, the type is left blank.
165
-
- The third value ``False`` is a flag that indicates whether or not the model also applies to all overrides of the method. For a free function, this should be ``False``.
208
+
- The third value ``false`` is a flag that indicates whether or not the model also applies to all overrides of the method. For a free function, this should be ``false``.
166
209
- The fourth value ``"buffer"`` is the function name.
167
210
- The fifth value is the function input type signature, which can be used to narrow down between functions that have the same name. In this case, we want the model to include all functions in ``boost::asio`` called ``buffer``.
168
211
@@ -190,20 +233,27 @@ This function escapes special characters in a string for use in an SQL statement
190
233
191
234
We need to add a tuple to the ``barrierModel(namespace, type, subtypes, name, signature, ext, output, kind, provenance)`` extensible predicate by updating a data extension file.
The first five values identify the callable (in this case a free function) to be modeled as a barrier.
203
253
204
254
- The first value ``""`` is the namespace name.
205
255
- The second value ``""`` is the name of the type (class) that contains the method. Because we're modeling a free function, the type is left blank.
206
-
- The third value ``False`` is a flag that indicates whether or not the model also applies to all overrides of the method. For a free function, this should be ``False``.
256
+
- The third value ``false`` is a flag that indicates whether or not the model also applies to all overrides of the method. For a free function, this should be ``false``.
207
257
- The fourth value ``"mysql_real_escape_string"`` is the function name.
208
258
- The fifth value is the function input type signature, which can be used to narrow down between functions that have the same name.
209
259
@@ -229,20 +279,27 @@ Consider a function called ``is_safe`` which returns ``true`` when the data is c
229
279
230
280
We need to add a tuple to the ``barrierGuardModel(namespace, type, subtypes, name, signature, ext, input, acceptingValue, kind, provenance)`` extensible predicate by updating a data extension file.
The first five values identify the callable (in this case a free function) to be modeled as a barrier guard.
242
299
243
300
- The first value ``""`` is the namespace name.
244
301
- The second value ``""`` is the name of the type (class) that contains the method. Because we're modeling a free function, the type is left blank.
245
-
- The third value ``False`` is a flag that indicates whether or not the model guard also applies to all overrides of the method. For a free function, this should be ``False``.
302
+
- The third value ``false`` is a flag that indicates whether or not the model guard also applies to all overrides of the method. For a free function, this should be ``false``.
246
303
- The fourth value ``"is_safe"`` is the function name.
247
304
- The fifth value is the function input type signature, which can be used to narrow down between functions that have the same name.
0 commit comments