Our ~35 own rules left whole languages without SAST findings. Three permissively licensed community packs now run next to them, on the same semgrep invocation (--metrics=off, local files only): - GitLab sast-rules v2.10.1 (53bf5cf6): 148 rules for C#, Java, JavaScript/TypeScript, Python and one Go rule; only files whose header says "License: MIT (c) GitLab Inc.". Not vendored: c/ (every file GPL-2.0, generated from flawfinder), go/ apart from one file (Apache-2.0 gosec ports), scala/, rules/lgpl, rules/lgpl-cc (Commons Clause), rules/gitlab (EE). - 0xdea semgrep-rules (dae50da6, MIT): 35 C/C++ rules. - elttam semgrep-rules (24426856, MIT; its LICENSE carries the Semgrep template's copyright line): 34 rules for Java, Go and Struts/Spring XML. Each pack lives in compliance-agent/rules/vendor/<source>/ with LICENSE, NOTICE (provenance, what was left out and why) and UPSTREAM (pinned commit): upstream/ holds the selected files unchanged with their tests, pack.yaml the rules the agent runs, ids prefixed per source (gitlab-, 0xdea-, elttam-), rules.json an index for the tests. scripts/vendor-semgrep-rules.py regenerates all of it deterministically. Provenance: every candidate rule was compared with the Semgrep registry (semgrep/semgrep-rules, read only for the comparison). Eight GitLab Python/JS rules with the same message or the same patterns are not vendored, nor are elttam's Kubernetes rules (registry-derived). Also left out: elttam's entrypoint enumerators, its ORM-leak hints, three files whose upstream tests fail on semgrep 1.177 and a join-mode rule. Noise budget: run over the nightly fixtures, the public samples and FreeRTOS-Kernel, lwIP, OpenRA, eShopOnWeb, requests, express and spring-petclinic. 15 rules that flood real code (0xdea missing-return 1514 hits, typos 989, interesting-api-calls 718, signed-unsigned-conversion 221, suspicious-assert 176, format-string-bugs 61 ...; GitLab assert-used) are dropped from the pack, each listed with its reason in NOTICE. CPU time of the semgrep run roughly doubles on C-heavy trees (FreeRTOS-Kernel 70 s -> 136 s, lwIP 18 s -> 68 s), well inside the 10-minute stage timeout. Ids stay bare (#473 logic covers the vendored ids, fingerprint() unchanged). The control map gets one vendored semgrep binding per control, by CWE (by rule id for the few elttam rules without one), with exactly the languages of the rules behind it; a test checks every vendored rule maps to a control that claims its languages. Guard: semgrep_args() builds the one invocation; a test fails if any --config is not a staged local pack, or is auto, p/, r/ or a URL, and another scans the agent source, scripts, docker/, CI and Dockerfile.agent for a registry config. Nightly baselines with C, Python, C# or JS code change and need a bless run after the image is deployed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit was merged in pull request #504.
This commit is contained in:
1 parent
9bf7aad5b1
commit
d406741907
473 files changed
+50690
-116
No files matched your search
+13
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python
|
||||
# License: MIT (c) GitLab Inc.
|
||||
|
||||
# ruleid: python_assert_rule-assert-used
|
||||
assert True
|
||||
|
||||
def test_function():
|
||||
# ruleid: python_assert_rule-assert-used
|
||||
assert 1 == 1
|
||||
|
||||
def test_function2():
|
||||
# ruleid: python_assert_rule-assert-used
|
||||
assert("test")
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
# yamllint disable
|
||||
# License: MIT (c) GitLab Inc.
|
||||
# yamllint enable
|
||||
---
|
||||
rules:
|
||||
- id: "python_assert_rule-assert-used"
|
||||
languages:
|
||||
- "python"
|
||||
message: |
|
||||
The application was found using `assert` in non-test code. Usually reserved for debug and test
|
||||
code, the `assert`
|
||||
function is commonly used to test conditions before continuing execution. However, enclosed
|
||||
code will be removed
|
||||
when compiling Python code to optimized byte code. Depending on the assertion and subsequent
|
||||
logic, this could
|
||||
lead to undefined behavior of the application or application crashes.
|
||||
|
||||
To remediate this issue, remove the `assert` calls. If necessary, replace them with either `if`
|
||||
conditions or
|
||||
`try/except` blocks.
|
||||
|
||||
Example using `try/except` instead of `assert`:
|
||||
```
|
||||
# Below try/except is equal to the assert statement of:
|
||||
# assert user.is_authenticated(), "user must be authenticated"
|
||||
try:
|
||||
if not user.is_authenticated():
|
||||
raise AuthError("user must be authenticated")
|
||||
except AuthError as e:
|
||||
# Handle error
|
||||
# ...
|
||||
# Return, do not continue processing
|
||||
return
|
||||
```
|
||||
metadata:
|
||||
cwe: "CWE-754"
|
||||
category: "security"
|
||||
shortDescription: "Improper check for unusual or exceptional conditions"
|
||||
owasp:
|
||||
- "A6:2017-Security Misconfiguration"
|
||||
- "A05:2021-Security Misconfiguration"
|
||||
- "A10:2025-Mishandling of Exceptional Conditions"
|
||||
security-severity: "Info"
|
||||
patterns:
|
||||
- pattern: "assert(...)"
|
||||
- pattern-not-inside: |
|
||||
import pytest
|
||||
...
|
||||
- pattern-not-inside: |
|
||||
import unittest
|
||||
...
|
||||
severity: "INFO"
|
||||
Reference in new issue
Block a user