Commit Graph

9254 Commits

Author SHA1 Message Date
Taus
2158eaa34c Python: Fix a bug in glob regex creation
The previous version was tested on a version of the code where we had
temporarily removed the `glob.strip("/")` bit, and so the bug didn't
trigger then.

We now correctly remember if the glob ends in `/`, and add an extra part
in that case. This way, if the path ends with multiple slashes, they
effectively get consolidated into a single one, which results in the
correct semantics.
2025-05-15 15:34:11 +00:00
Taus
c8cca126a1 Python: Bump extractor version 2025-05-15 14:59:33 +00:00
Taus
72ae633a64 Python: Update change note and extractor config
Removes the previously added extractor option and updates the change
note to explain how to use `paths-ignore` to exclude files in hidden
directories.
2025-05-15 14:58:32 +00:00
Taus
96558b53b8 Python: Update test
The second test case now sets the `paths-ignore` setting in the config
file in order to skip files in hidden directories.
2025-05-15 14:53:15 +00:00
Taus
98388be25c Python: Remove special casing of hidden files
If it is necessary to exclude hidden files, then adding
```
paths-ignore: ['**/.*/**']
```
to the relevant config file is recommended instead.
2025-05-15 14:49:17 +00:00
Taus
61719cf448 Python: Fix a bug in glob conversion
If you have a filter like `**/foo/**` set in the `paths-ignore` bit of
your config file, then currently the following happens:

- First, the CodeQL CLI observes that this string ends in `/**` and
  strips off the `**` leaving `**/foo/`
- Then the Python extractor strips off leading and trailing `/`
  characters and proceeds to convert `**/foo` into a regex that is
  matched against files to (potentially) extract.

The trouble with this is that it leaves us unable to distinguish
between, say, a file `foo.py` and a file `foo/bar.py`. In other words,
we have lost the ability to exclude only the _folder_ `foo` and not any
files that happen to start with `foo`.

To fix this, we instead make a note of whether the glob ends in a
forward slash or not, and adjust the regex correspondingly.
2025-05-15 14:48:06 +00:00
Taus
2ded42c285 Python: Update extractor tests 2025-05-02 14:27:46 +00:00
Taus
67d04d5477 Python: Add change note 2025-05-02 14:27:46 +00:00
Taus
605f2bff9c Python: Add integration test 2025-05-02 14:27:46 +00:00
Taus
0c1b379ac1 Python: Extract files in hidden dirs by default
Changes the default behaviour of the Python extractor so files inside
hidden directories are extracted by default.

Also adds an extractor option, `skip_hidden_directories`, which can be
set to `true` in order to revert to the old behaviour.

Finally, I made the logic surrounding what is logged in various cases a
bit more obvious.

Technically this changes the behaviour of the extractor (in that hidden
excluded files will now be logged as `(excluded)`, but I think this
makes more sense anyway.
2025-05-02 12:44:05 +00:00
Joe Farebrother
299b3f7af4 Merge pull request #19325 from joefarebrother/python-qual-loop-var-capture
Python: Tweak LoopVariableCapture for performance
2025-04-29 13:49:09 +01:00
Tamas Vajk
a408e216ae Add query suite inclusion tests for cpp, python 2025-04-29 08:45:01 +02:00
github-actions[bot]
2e0699ab2b Post-release preparation for codeql-cli-2.21.2 2025-04-28 14:03:28 +00:00
github-actions[bot]
625354c46e Release preparation for version 2.21.2 2025-04-28 10:55:22 +00:00
Chuan-kai Lin
6c1e80df3a Python: disable diff-informed PolynomialReDoS.ql
This commit disabled diff-informed for PolynomialReDoS.ql because it
could miss some alerts within diff ranges.
2025-04-24 14:57:06 -07:00
Joe Farebrother
6431228d37 Limit size of allowImplicitRead for performance 2025-04-16 09:40:01 +01:00
github-actions[bot]
d78736b1bf Post-release preparation for codeql-cli-2.21.1 2025-04-15 16:33:15 +00:00
github-actions[bot]
b961c5961d Release preparation for version 2.21.1 2025-04-14 09:53:06 +00:00
Joe Farebrother
7f7fca9e27 Merge pull request #19165 from joefarebrother/python-qual-loop-var-capture
Python: Modernize the Loop Variable Capture query
2025-04-10 13:07:05 +01:00
Joe Farebrother
6802037c89 Update qhelp formatting 2025-04-10 09:52:18 +01:00
Joe Farebrother
00999baf9a Apply docs review suggestion - Reword query description.
Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com>
2025-04-10 09:06:01 +01:00
Joe Farebrother
84aa2e8627 Apply review suggestion - Tweak wording of example comment
Co-authored-by: Taus <tausbn@github.com>
2025-04-09 14:07:38 +01:00
Joe Farebrother
e08072d77b Fix qhelp formatting 2025-04-04 12:51:46 +01:00
Joe Farebrother
de7e611962 Rewrite documentation 2025-04-04 12:36:13 +01:00
Joe Farebrother
b5805503fe Cleanups 2025-04-04 11:56:07 +01:00
Joe Farebrother
9fb1c31206 Update tests to inline expectations 2025-04-04 10:13:39 +01:00
Joe Farebrother
adfe89fadc Update test output 2025-04-04 09:47:21 +01:00
Joe Farebrother
c37809a187 Reduce scope of allowImplicitRead to avoid cartesian product. 2025-04-02 09:35:50 +01:00
Joe Farebrother
2d6476ad21 Update names and alert message 2025-04-02 09:35:43 +01:00
Joe Farebrother
11830bf661 Move to separate folder 2025-04-02 09:35:39 +01:00
Joe Farebrother
5b7200a041 Use flow path in alerts 2025-04-02 09:35:32 +01:00
Joe Farebrother
08b4281187 Update query message and remove field case 2025-04-02 09:35:25 +01:00
Joe Farebrother
efdb4a6d82 Use global dataflow for loop variable capture 2025-04-02 09:35:17 +01:00
Taus
aacdc70a73 Merge pull request #19136 from github/tausbn/python-modernise-mixed-tuple-returns-query
Python: Modernize `py/mixed-tuple-returns`
2025-04-01 17:31:56 +02:00
Arthur Baars
0e23b86bf5 Merge pull request #19182 from github/post-release-prep/codeql-cli-2.21.0
Post-release preparation for codeql-cli-2.21.0
2025-04-01 15:12:29 +02:00
github-actions[bot]
10205cb990 Post-release preparation for codeql-cli-2.21.0 2025-04-01 11:30:43 +00:00
Joe Farebrother
73eebcbca6 Python: Add file-not-closed and special-method-wrong-signature to python code-quality suite 2025-04-01 10:05:17 +01:00
github-actions[bot]
84f6564cc0 Release preparation for version 2.21.0 2025-03-31 17:35:15 +00:00
Taus
840abbf5b1 Merge pull request #18956 from github/tausbn/python-more-special-method-query-refactoring
Python: Modernize special method query
2025-03-28 17:11:24 +01:00
Taus
6674288fd2 Python: Update test cases
Adds a comment explaining why we no longer flag the indirect tuple
example.
Also adds a test case which _would_ be flagged if not for the type
annotation.
2025-03-28 15:12:39 +00:00
Joe Farebrother
43567664bf Merge pull request #18845 from joefarebrother/python-qual-file-not-closed
Python: Modernize File Not Always Closed query
2025-03-28 14:47:38 +00:00
Taus
68668b8e22 Python: Fix grammar in change note 2025-03-27 23:23:29 +01:00
Joe Farebrother
2fd9b16736 Attempt performance improvement for fileLocalFlow 2025-03-27 15:45:38 +00:00
Taus
980c7d83da Python: Add change note 2025-03-27 15:33:00 +00:00
Taus
f601f4ad9b Python: Update test expectations
As we're no longer tracking tuples across function boundaries, we lose
the result that related to this setup (which, as the preceding commit
explains, lead to a lot of false positives).
2025-03-27 15:31:28 +00:00
Taus
2dcd7895ec Python: Modernise py/mixed-tuple-returns
Removes the dependence on points-to in favour of an approach based on
(local) data-flow.

I first tried a version that used type tracking, as this more accurately
mimics the behaviour of the old query. However, I soon discovered that
there were _many_ false positives in this setup. The main bad pattern I
saw was a helper function somewhere deep inside the code that both
receives and returns an argument that can be tuples with different sizes
and origins. In this case, global flow produces something akin to a
cartesian product of "n-tuples that flow into the function" and
"m-tuples that flow into the function" where m < n.

To combat this, I decided to instead focus on only flow _within_ a given
function (and so local data-flow was sufficient).

Additionally, another class of false positives I saw was cases where the
return type actually witnessed that the function in question could
return tuples of varying sizes. In this case it seems reasonable to not
flag these instances, since they are already (presumably) being checked
by a type checker.

More generally, if you've annotated the return type of the function with
anything (not just `Tuple[...]`), then there's probably little need to
flag it.
2025-03-27 15:27:42 +00:00
Arthur Baars
9dd7b20db7 Merge pull request #18960 from github/aibaars/rust-tainted-path
Rust: TaintedPath query
2025-03-27 10:37:36 +01:00
Tamas Vajk
34e8318797 Rename the CCR query suite to code-quality 2025-03-27 08:36:53 +01:00
Joe Farebrother
d23c3b8a74 Revert manual magic
This appeared to cause timeouts on DCA.
2025-03-26 09:23:49 +00:00
Joe Farebrother
0fa70db4c2 Review suggestions - update comment and introduce manual magic to filelocalflow 2025-03-25 08:55:55 +00:00