Skip to content

Commit d8dad7d

Browse files
author
Paolo Tranquilli
committed
Merge branch 'main' into redsun82/rust-trait-path
2 parents 1bce783 + 8ef2029 commit d8dad7d

File tree

16 files changed

+881
-363
lines changed

16 files changed

+881
-363
lines changed

cpp/ql/src/Security/CWE/CWE-078/ExecTainted.ql

+16-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ predicate interestingConcatenation(DataFlow::Node incoming, DataFlow::Node outgo
4949
call.getTarget() = op and
5050
op.hasQualifiedName("std", "operator+") and
5151
op.getType().(UserType).hasQualifiedName("std", "basic_string") and
52-
incoming.asIndirectArgument() = call.getArgument(1) and // left operand
52+
incoming.asIndirectArgument() = call.getArgument(1) and // right operand
5353
call = outgoing.asInstruction().getUnconvertedResultExpression()
5454
)
5555
}
5656

57+
/**
58+
* A state will represent the most recent concatenation that occurred in the data flow.
59+
* - `TConcatState` if the concetenation has not yet occurred.
60+
* - `TExecState(incoming, outgoing)`, representing the concatenation of data from `incoming`
61+
* into result `outgoing`.
62+
*/
5763
newtype TState =
5864
TConcatState() or
5965
TExecState(DataFlow::Node incoming, DataFlow::Node outgoing) {
@@ -74,7 +80,9 @@ class ExecState extends TExecState {
7480

7581
DataFlow::Node getOutgoingNode() { result = outgoing }
7682

77-
/** Holds if this is a possible `ExecState` for `sink`. */
83+
/**
84+
* Holds if this is a possible `ExecState` at `sink`, that is, if `outgoing` flows to `sink`.
85+
*/
7886
predicate isFeasibleForSink(DataFlow::Node sink) { ExecState::flow(outgoing, sink) }
7987

8088
string toString() { result = "ExecState" }
@@ -110,6 +118,12 @@ module ExecStateConfig implements DataFlow::ConfigSig {
110118

111119
module ExecState = TaintTracking::Global<ExecStateConfig>;
112120

121+
/**
122+
* A full `TaintTracking` configuration from source to concatenation to sink, using a flow
123+
* state to remember the concatenation. It's important that we track flow to the sink even though
124+
* as soon as we reach the concatenation we know it will get there (due to the check of
125+
* `isFeasibleForSink`), because this way we get a complete flow path.
126+
*/
113127
module ExecTaintConfig implements DataFlow::StateConfigSig {
114128
class FlowState = TState;
115129

cpp/ql/test/query-tests/Security/CWE/CWE-078/semmle/ExecTainted/ExecTainted.expected

+205-153
Large diffs are not rendered by default.

cpp/ql/test/query-tests/Security/CWE/CWE-078/semmle/ExecTainted/test.cpp

+46-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern void encodeShellString(char *shellStr, int maxChars, const char* cStr);
1414

1515
int main(int argc, char** argv) {
1616
char *userName = argv[2];
17-
17+
1818
{
1919
// BAD: a string from the user is injected directly into
2020
// a command.
@@ -23,10 +23,10 @@ int main(int argc, char** argv) {
2323
system(command1);
2424
}
2525

26-
{
26+
{
2727
// GOOD: the user string is encoded by a library routine.
2828
char userNameQuoted[1000] = {0};
29-
encodeShellString(userNameQuoted, 1000, userName);
29+
encodeShellString(userNameQuoted, 1000, userName);
3030
char command2[1000] = {0};
3131
sprintf(command2, "userinfo -v %s", userNameQuoted);
3232
system(command2);
@@ -36,16 +36,16 @@ int main(int argc, char** argv) {
3636
void test2(char* arg2) {
3737
// GOOD?: the user string is the *first* part of the command, like $CC in many environments
3838
char *envCC = getenv("CC");
39-
39+
4040
char command[1000];
41-
sprintf("%s %s", envCC, arg2);
41+
sprintf(command, "%s %s", envCC, arg2);
4242
system(command);
4343
}
4444

4545
void test3(char* arg1) {
4646
// GOOD?: the user string is a `$CFLAGS` environment variable
4747
char *envCflags = getenv("CFLAGS");
48-
48+
4949
char command[1000];
5050
sprintf(command, "%s %s", arg1, envCflags);
5151
system(command);
@@ -54,6 +54,7 @@ void test3(char* arg1) {
5454
typedef unsigned long size_t;
5555
typedef void FILE;
5656
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
57+
char *strncpy(char *s1, const char *s2, size_t n);
5758
char *strncat(char *s1, const char *s2, size_t n);
5859

5960
void test4(FILE *f) {
@@ -160,7 +161,7 @@ void test15(FILE *f) {
160161
fread(temp, 1, 10, f);
161162

162163
int x = atoi(temp);
163-
164+
164165
char temp2[10];
165166
sprintf(temp2, "%d", x);
166167
sprintf(command, "tail -n %s foo.log", temp2);
@@ -222,4 +223,42 @@ void test19(FILE *f) {
222223
execl("/bin/sh", "sh", "-c", command);
223224
}
224225

226+
void test20() {
227+
// BAD: the user strings `var_b`, `var_c` are injected directly into a command
228+
char buffer[1024 * 4];
229+
230+
strncpy(buffer, getenv("var_a"), 1024);
231+
strncat(buffer, getenv("var_b"), 1024);
232+
strncat(buffer, getenv("var_c"), 1024);
233+
strncat(buffer, " ", 1024);
234+
system(buffer);
235+
}
236+
237+
void test21() {
238+
// BAD: the user strings `var_b`, `var_c` are injected directly into a command
239+
char buffer1[1024];
240+
char buffer2[1024];
241+
242+
sprintf(buffer1, "%s %s",
243+
getenv("var_a"),
244+
getenv("var_b"));
245+
sprintf(buffer2, "%s %s %s",
246+
" ",
247+
buffer1,
248+
getenv("var_c"));
249+
system(buffer2);
250+
}
251+
252+
void test22() {
253+
// BAD: the user strings `var_a` are injected directly into a command
254+
char buffer[1024 * 11];
255+
int i;
256+
257+
strncpy(buffer, "command ", 1024);
258+
for (i = 0; i < 10; i++) {
259+
strncat(buffer, getenv("var_a"), 1024);
260+
}
261+
system(buffer);
262+
}
263+
225264
// open question: do we want to report certain sources even when they're the start of the string?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
.. _codeql-cli-2.20.5:
2+
3+
==========================
4+
CodeQL 2.20.5 (2025-02-20)
5+
==========================
6+
7+
.. contents:: Contents
8+
:depth: 2
9+
:local:
10+
:backlinks: none
11+
12+
This is an overview of changes in the CodeQL CLI and relevant CodeQL query and library packs. For additional updates on changes to the CodeQL code scanning experience, check out the `code scanning section on the GitHub blog <https://github.blog/tag/code-scanning/>`__, `relevant GitHub Changelog updates <https://github.blog/changelog/label/code-scanning/>`__, `changes in the CodeQL extension for Visual Studio Code <https://marketplace.visualstudio.com/items/GitHub.vscode-codeql/changelog>`__, and the `CodeQL Action changelog <https://github.com/github/codeql-action/blob/main/CHANGELOG.md>`__.
13+
14+
Security Coverage
15+
-----------------
16+
17+
CodeQL 2.20.5 runs a total of 450 security queries when configured with the Default suite (covering 168 CWE). The Extended suite enables an additional 136 queries (covering 34 more CWE). 4 security queries have been added with this release.
18+
19+
CodeQL CLI
20+
----------
21+
22+
Breaking Changes
23+
~~~~~~~~~~~~~~~~
24+
25+
* Removed support for :code:`QlBuiltins::BigInt`\ s in the :code:`avg()` aggregate.
26+
27+
* A number of breaking changes have been made to the C and C++ CodeQL test environment as used by :code:`codeql test run`\ :
28+
29+
* The :code:`-Xclang-only=<arg>` option is no longer supported by :code:`semmle-extractor-options`. Instead, when either :code:`--clang` or :code:`--clang_version` is specified the option should be replaced by :code:`<arg>` only, otherwise the option should be omitted.
30+
* The :code:`--sys_include <arg>` and :code:`--preinclude <arg>` options are no longer supported by :code:`semmle-extractor-options`. Instead, :code:`--edg <option_name> --edg <arg>` should be specified.
31+
* The :code:`-idirafter <arg>` option is no longer supported by :code:`semmle-extractor-options`. Instead, :code:`--edg --sys_include --edg <arg>` should be specified.
32+
* The :code:`-imacros <arg>` option is no longer supported by :code:`semmle-extractor-options`. Instead, :code:`--edg --preinclude_macros --edg <arg>` should be specified.
33+
* The :code:`/FI <arg>` option is no longer supported by :code:`semmle-extractor-options`. Instead, :code:`--edg --preinclude --edg <arg>` should be specified.
34+
* The :code:`-Wreserved-user-defined-literal`, :code:`-Wno-reserved-user-defined-literal`, :code:`-fwritable-strings`, :code:`/Zc:rvalueCast`, :code:`/Zc:rvalueCast-`, and :code:`/Zc:wchar_t-` options are no longer supported by :code:`semmle-extractor-options`. Instead, :code:`--edg --reserved_user_defined_literal`, :code:`--edg --no-reserved_user_defined_literal`, :code:`--edg --no_const_string_literals`, :code:`--edg --no_preserve_lvalues_with_same_type_casts`, :code:`--edg --preserve_lvalues_with_same_type_casts`, and :code:`--edg --no_wchar_t_keyword` should be specified, respectively.
35+
* The :code:`/Fo <arg>` option is no longer supported by :code:`semmle-extractor-options`. The option should be omitted.
36+
37+
Query Packs
38+
-----------
39+
40+
Bug Fixes
41+
~~~~~~~~~
42+
43+
JavaScript/TypeScript
44+
"""""""""""""""""""""
45+
46+
* Fixed a recently-introduced bug that prevented taint tracking through :code:`URLSearchParams` objects.
47+
The original behaviour has been restored and taint should once again be tracked through such objects.
48+
* Fixed a rare issue that would occur when a function declaration inside a block statement was referenced before it was declared.
49+
Such code is reliant on legacy web semantics, which is non-standard but nevertheless implemented by most engines.
50+
CodeQL now takes legacy web semantics into account and resolves references to these functions correctly.
51+
* Fixed a bug that would cause parse errors in :code:`.jsx` files in rare cases where the file contained syntax that was misinterpreted as Flow syntax.
52+
53+
Breaking Changes
54+
~~~~~~~~~~~~~~~~
55+
56+
GitHub Actions
57+
""""""""""""""
58+
59+
* The following queries have been removed from the :code:`code-scanning` and :code:`security-extended` suites.
60+
Any existing alerts for these queries will be closed automatically.
61+
62+
* :code:`actions/if-expression-always-true/critical`
63+
* :code:`actions/if-expression-always-true/high`
64+
* :code:`actions/unnecessary-use-of-advanced-config`
65+
66+
* The following query has been moved from the :code:`code-scanning` suite to the :code:`security-extended` suite. Any existing alerts for this query will be closed automatically unless the analysis is configured to use the :code:`security-extended` suite.
67+
68+
* :code:`actions/unpinned-tag`
69+
70+
* The following queries have been added to the :code:`security-extended` suite.
71+
72+
* :code:`actions/unversioned-immutable-action`
73+
* :code:`actions/envpath-injection/medium`
74+
* :code:`actions/envvar-injection/medium`
75+
* :code:`actions/code-injection/medium`
76+
* :code:`actions/artifact-poisoning/medium`
77+
* :code:`actions/untrusted-checkout/medium`
78+
79+
Minor Analysis Improvements
80+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
81+
82+
Golang
83+
""""""
84+
85+
* Added `github.com/gorilla/mux.Vars <https://pkg.go.dev/github.com/gorilla/mux#Vars>`__ to path sanitizers (disabled if `github.com/gorilla/mix.Router.SkipClean <https://pkg.go.dev/github.com/gorilla/mux#Router.SkipClean>`__ has been called).
86+
87+
GitHub Actions
88+
""""""""""""""
89+
90+
* Fixed false positives in the query :code:`actions/unpinned-tag` (CWE-829), which will no longer flag uses of Docker-based GitHub actions pinned by the container's SHA256 digest.
91+
92+
New Queries
93+
~~~~~~~~~~~
94+
95+
Java/Kotlin
96+
"""""""""""
97+
98+
* Added a new query, :code:`java/csrf-unprotected-request-type`, to detect Cross-Site Request Forgery (CSRF) vulnerabilities due to using HTTP request types that are not default-protected from CSRF.
99+
100+
Language Libraries
101+
------------------
102+
103+
Bug Fixes
104+
~~~~~~~~~
105+
106+
Python
107+
""""""
108+
109+
* Fixed a bug in the extractor where a comment inside a subscript could sometimes cause the AST to be missing nodes.
110+
* Using the :code:`break` and :code:`continue` keywords outside of a loop, which is a syntax error but is accepted by our parser, would cause the control-flow construction to fail. This is now no longer the case.
111+
112+
Minor Analysis Improvements
113+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
114+
115+
C#
116+
""
117+
118+
* Full support for C# 13 / .NET 9. All new language features are now supported by the extractor. QL library and data flow support for the new C# 13 language constructs and generated MaD models for the .NET 9 runtime.
119+
* C# 13: Add generated models for .NET 9.
120+
* The models for :code:`System.Net.Http.HttpRequestMessage` and :code:`System.UriBuilder` have been modified to better model the flow of tainted URIs.
121+
* Blazor :code:`[Parameter]` fields bound to a variable from the route specified in the :code:`@page` directive are now modeled as remote flow sources.
122+
123+
Golang
124+
""""""
125+
126+
* Taint models have been added for the :code:`weak` package, which was added in Go 1.24.
127+
* Taint models have been added for the interfaces :code:`TextAppender` and :code:`BinaryAppender` in the :code:`encoding` package, which were added in Go 1.24.
128+
129+
JavaScript/TypeScript
130+
"""""""""""""""""""""
131+
132+
* Added support for regular expressions using the :code:`v` flag.
133+
134+
Deprecated APIs
135+
~~~~~~~~~~~~~~~
136+
137+
C#
138+
""
139+
140+
* The predicates :code:`immediatelyControls` and :code:`controls` on the :code:`ConditionBlock` class have been deprecated in favor of the newly added :code:`dominatingEdge` predicate.
141+
142+
Golang
143+
""""""
144+
145+
* The class :code:`NamedType` has been deprecated. Use the new class :code:`DefinedType` instead. This better matches the terminology used in the Go language specification, which was changed in Go 1.9.
146+
* The member predicate :code:`getNamedType` on :code:`GoMicro::ServiceInterfaceType` has been deprecated. Use the new member predicate :code:`getDefinedType` instead.
147+
* The member predicate :code:`getNamedType` on :code:`Twirp::ServiceInterfaceType` has been deprecated. Use the new member predicate :code:`getDefinedType` instead.
148+
149+
Ruby
150+
""""
151+
152+
* The predicates :code:`immediatelyControls` and :code:`controls` on the :code:`ConditionBlock` class have been deprecated in favor of the newly added :code:`dominatingEdge` predicate.
153+
154+
Swift
155+
"""""
156+
157+
* The predicates :code:`immediatelyControls` and :code:`controls` on the :code:`ConditionBlock` class have been deprecated in favor of the newly added :code:`dominatingEdge` predicate.
158+
159+
New Features
160+
~~~~~~~~~~~~
161+
162+
GitHub Actions
163+
""""""""""""""
164+
165+
* The "Unpinned tag for a non-immutable Action in workflow" query (:code:`actions/unpinned-tag`) now supports expanding the trusted action owner list using data extensions (:code:`extensible: trustedActionsOwnerDataModel`). If you trust an Action publisher, you can include the owner name/organization in a model pack to add it to the allow list for this query. This addition will prevent security alerts when using unpinned tags for Actions published by that owner. For more information on creating a model pack, see `Creating a CodeQL 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>`__.

docs/codeql/codeql-overview/codeql-changelog/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A list of queries for each suite and language `is available here <https://docs.g
1111
.. toctree::
1212
:maxdepth: 1
1313

14+
codeql-cli-2.20.5
1415
codeql-cli-2.20.4
1516
codeql-cli-2.20.3
1617
codeql-cli-2.20.2

rust/ast-generator/BUILD.bazel

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ write_file(
6666
'DST_DIR="$(dirname "$(rlocation "$1")")"',
6767
'mkdir -p "$DST_DIR/src/codegen/grammar"',
6868
] + [
69-
'cp -f --no-preserve=mode "$(rlocation "$%s")" "$DST_DIR/%s"' % item
69+
# using cat instead of cp to honor default umask
70+
# (also, macOS does not support `cp --no-preserve=mode`)
71+
'cat "$(rlocation "$%s")" > "$DST_DIR/%s"' % item
7072
for item in enumerate(_codegen_outs, 2)
7173
],
7274
is_executable = True,

rust/extractor/macros/src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ pub fn extractor_cli_config(_attr: TokenStream, item: TokenStream) -> TokenStrea
1919
.fields
2020
.iter()
2121
.map(|f| {
22+
let ty_tip = get_type_tip(&f.ty);
2223
if f.ident.as_ref().is_some_and(|i| i != "inputs")
23-
&& get_type_tip(&f.ty).is_some_and(|i| i == "Vec")
24+
&& ty_tip.is_some_and(|i| i == "Vec")
2425
{
2526
quote! {
26-
#[serde(deserialize_with="deserialize_newline_or_comma_separated")]
27+
#[serde(deserialize_with="deserialize::deserialize_newline_or_comma_separated_vec")]
28+
#f
29+
}
30+
} else if ty_tip.is_some_and(|i| i == "FxHashMap" || i == "HashMap") {
31+
quote! {
32+
#[serde(deserialize_with="deserialize::deserialize_newline_or_comma_separated_map")]
2733
#f
2834
}
2935
} else {
@@ -60,7 +66,7 @@ pub fn extractor_cli_config(_attr: TokenStream, item: TokenStream) -> TokenStrea
6066
quote! {
6167
#f
6268
}
63-
} else if type_tip.is_some_and(|i| i == "Vec") {
69+
} else if type_tip.is_some_and(|i| i == "Vec" || i == "FxHashMap" || i == "HashMap") {
6470
quote! {
6571
#[arg(long)]
6672
#id: Option<String>

0 commit comments

Comments
 (0)