Commit Graph

9221 Commits

Author SHA1 Message Date
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
Joe Farebrother
a46c157e46 Add quality tag + tweak description 2025-03-21 09:24:54 +00:00
Joe Farebrother
bdbdcf8bd8 Clean up charpred of WithStatement + fix a comment 2025-03-20 14:28:57 +00:00
Taus
074af6f548 Python: Add change note 2025-03-20 13:57:32 +00:00
Joe Farebrother
3707f107bf Fix tests + add more tests 2025-03-20 11:35:38 +00:00
Joe Farebrother
2c74ddb853 Add django FileRsponse as a wrapper 2025-03-20 11:35:29 +00:00
Joe Farebrother
b2acfbcf87 Simplify handling of wrapper classes and exception flow + improve qldoc and annotate tests. 2025-03-20 11:35:18 +00:00
Joe Farebrother
f8a0b1c5f9 Update docs, precision, and deprecate old library 2025-03-20 11:35:12 +00:00
Joe Farebrother
f750e22d91 Add case for exception flow 2025-03-20 11:35:01 +00:00
Joe Farebrother
c8fc56560d Check for wrapper classes 2025-03-20 11:34:51 +00:00
Joe Farebrother
ecb3050780 Update tests 2025-03-20 11:34:42 +00:00
Joe Farebrother
09694c448d Rewrite file not closed simple case using dataflow 2025-03-20 11:34:33 +00:00
Arthur Baars
d3e28772ae Rust/Python improve qldoc of SafeAccessCheck 2025-03-20 11:16:45 +01:00
Chris Smowton
9a2a13ed55 Merge remote-tracking branch 'origin/main' into smowton/admin/merge-rc317-into-main 2025-03-19 16:01:29 +00:00
github-actions[bot]
51cdeefafb Post-release preparation for codeql-cli-2.20.7 2025-03-17 13:00:41 +00:00
github-actions[bot]
2d64a618e6 Release preparation for version 2.20.7 2025-03-17 12:15:54 +00:00
Taus
ef9b229023 Python: Actually get rid of points-to
Also adds `quality` to the list of tags for the query.
2025-03-14 16:51:48 +00:00
Taus
c9e9deb41e Python: Adapt to a points-to-less world
Technically we still depend on points-to in that we still mention
`PythonFunctionValue` and `ClassValue` in the query. However, we
immediately move to working with the corresponding `Function` and
`Class` AST nodes, and so we're not really using points-to. (The reason
for doing things this way is that otherwise the `.toString()` for all of
the alerts would change, which would make the diff hard to interpret.
This way, it should be fairly simple to see which changes are actually
relevant.)

We do lose some precision when moving away from points-to, and this is
reflected in the changes in the `.expected` file. In particular we no
longer do complicated tracking of values, but rather look at the
syntactic structure of the classes in question. This causes us to lose
out on some results where a special method is defined elsewhere, and
causes a single FP where a special method initially has the wrong
signature, but is subsequently overwritten with a function with the
correct signature.

We also lose out on results having to do with default values, as these
are now disabled.

Finally, it was necessary to add special handling of methods marked with
the `staticmethod` decorator, as these expect to receive fewer
arguments. This was motivated by a MRVA run, where e.g. sympy showed a
lot of examples along the lines of
```
@staticmethod
def __abs__():
   return ...
```
2025-03-14 16:49:33 +00:00
Taus
bf688b88a9 Python: Add missing special methods 2025-03-14 16:29:54 +00:00
Taus
3d643c02be Merge pull request #18921 from github/tausbn/python-fix-unused-global-variable-in-forward-annotation-fp
Python: Add support for forward references in unused var query
2025-03-13 16:37:25 +01:00
Taus
f3353dc3fb Python: Ignore special methods with placeholder bodies
Instances of this include
- Bodies that contain just a docstring (common in Zope interfaces)
- Bodies that do nothing but raise an exception.
2025-03-13 12:18:43 +00:00
Taus
862b89207d Python: Disable "usused default" logic
Adds a new boolean parameter `is_unused_default` that indicates whether
the given result is one where a parameter to a special method has a
default value (which will never be used when invoked in the normal way).
These results are somewhat less useful (because the special method
_might_ be invoked directly, in which case the default value would still
be relevant), but it seemed like a shame to simply remove the code, so
instead I opted to disable it in this way.
2025-03-13 12:18:43 +00:00
Taus
24b2eb24c1 Python: Refactor special method query
Moves a bunch of `owner.declaredAttribute(name) = f` instances to the
top level, in the process greatly cleaning up the code. The behaviour
should be the unchanged.

Having done this, there's only one place where we depend on points-to,
and that's in the remaining `declaredAttribute` call. This should
greatly simplify the move away from points to.
2025-03-13 12:18:43 +00:00
Taus
f30ebf1571 Merge pull request #18871 from github/tausbn/python-modernise-special-method-signature-query
Python: Move min/maxParameter methods to `Function` class
2025-03-13 13:03:21 +01:00
yoff
10a9b78bc5 Merge pull request #18738 from github/tausbn/python-fix-match-pruning-logic
Python: Don't prune any `MatchLiteralPattern`s
2025-03-12 20:01:26 +01:00
yoff
a5101bdae6 Merge pull request #18855 from Kwstubbs/ssrf_documentation
Python: Add more documentation in regards to SSRF
2025-03-12 15:27:01 +01:00
Taus
6546bb1b1d Merge branch 'main' into tausbn/python-fix-match-pruning-logic 2025-03-06 14:37:58 +01:00
Taus
a9ab39da1b Merge pull request #18448 from github/tausbn/python-add-type-annotation-metrics-query
Python: Add metrics query for type annotations
2025-03-06 13:52:26 +01:00
Joe Farebrother
2692b8fa9f Merge pull request #18936 from joefarebrother/python-add-not-named-self-cls-ccr
Python: Include `py/not-named-self` and `py/not-named-cls` in the CCR suite
2025-03-06 09:51:14 +00:00
Joe Farebrother
a06de21f45 Python: Include py/not-named-self and py/not-named-cls in the CCR suite. 2025-03-05 15:13:20 +00:00
Taus
bf3d9ee6a9 Python: Address review comments 2025-03-04 22:30:55 +00:00
Taus
f246ef764a Python: Update change note
Co-authored-by: Aditya Sharad <6874315+adityasharad@users.noreply.github.com>
2025-03-04 18:09:54 +01:00
Taus
50a01b1244 Python: Remove superfluous reference to FunctionExpr
This way we also get annotations that appear in `Lambda`s
2025-03-04 15:53:34 +00:00
Taus
5d3b40d514 Python: Add change note 2025-03-04 14:47:03 +00:00