Repository navigation
fix: catch disabled TLS checks in session calls - #412
Conversation
Take over FOCA's shared semgrep rules as widened in elixir-cloud-aai/foca#784 (identical apart from `paths`), with their tests, and run the rule tests in pre-commit: - flask-debug-enabled (now also `debug: 1`), jwt-decode-without-verification (any falsy value, PyJWT instances and `decode_complete()`, assigned options), and the new jwt-decode-unsafe-algorithms (taint mode), yaml-unsafe-load and tls-verification-disabled (also calls on sessions, e.g. session.get(url, verify=False)) - ast-grep: string-status-code (returned tuples in parentheses, prefixed strings) and the new root-logger-call, as in proWES The rules find nothing in the code. The development guide mentions the rule tests and the root logger rule. Part of elixir-cloud-aai/foca#783 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideImplementationAdd Semgrep checks for insecure TLS verification, unsafe JWT decoding and algorithms, unsafe YAML loading, and enabled Flask debug mode, with expanded falsy-value detection.
Expand the AST-grep status-code rule to cover parenthesized return tuples and prefixed string codes, and add a rule flagging root-logger calls.
ConfigurationConfigure pre-commit to run Semgrep checks while excluding intentional-finding fixtures from the regular scan hook.
DocumentationDocument the project-specific Semgrep and AST-grep rules and note that they have tests.
TestsAdd Semgrep fixtures covering the security rules and Flask debug configuration cases.
Add AST-grep tests for root-logger calls and expand status-code cases for parenthesized tuples and prefixed strings.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Take over the changes of FOCA's shared semgrep rules from the review of elixir-cloud-aai/foca#784: - tls-verification-disabled: also 0.0, [] and {} in calls, and None as the session's setting - jwt-decode-without-verification: also [] and {} - jwt-decode-unsafe-algorithms: report `none` also inside a set difference Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #412 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 28 28
Lines 3517 3517
=========================================
Hits 3517 3517 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 60437d3 #413 fix: catch disabled TLS checks in session calls · 4 of 4 met
|
There was a problem hiding this comment.
Hey - I've found 9 security issues, and 7 other issues
Security issues:
- Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified. (link)
- Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified. (link)
- Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified. (link)
- Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified. (link)
- Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified. (link)
- Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified. (link)
- Detected a possible YAML deserialization vulnerability.
yaml.unsafe_load,yaml.Loader,yaml.CLoader, andyaml.UnsafeLoaderare all known to be unsafe methods of deserializing YAML. An attacker with control over the YAML input could create special YAML input that allows the attacker to run arbitrary Python code. This would allow the attacker to steal files, download and install malware, or otherwise take over the machine. Useyaml.safe_loadoryaml.SafeLoaderinstead. (link) - Detected a possible YAML deserialization vulnerability.
yaml.unsafe_load,yaml.Loader,yaml.CLoader, andyaml.UnsafeLoaderare all known to be unsafe methods of deserializing YAML. An attacker with control over the YAML input could create special YAML input that allows the attacker to run arbitrary Python code. This would allow the attacker to steal files, download and install malware, or otherwise take over the machine. Useyaml.safe_loadoryaml.SafeLoaderinstead. (link) - Detected a possible YAML deserialization vulnerability.
yaml.unsafe_load,yaml.Loader,yaml.CLoader, andyaml.UnsafeLoaderare all known to be unsafe methods of deserializing YAML. An attacker with control over the YAML input could create special YAML input that allows the attacker to run arbitrary Python code. This would allow the attacker to steal files, download and install malware, or otherwise take over the machine. Useyaml.safe_loadoryaml.SafeLoaderinstead. (link)
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".semgrep/cloud-registry.yml" line_range="86" />
<code_context>
+ - pattern: '"=~/^[nN][oO][nN][eE]$/"'
+ pattern-sinks:
+ - patterns:
+ - pattern: $JWT.$DECODE(..., algorithms=$ALGORITHMS, ...)
+ - metavariable-regex:
+ metavariable: $DECODE
</code_context>
<issue_to_address>
**Positional calls evade verification checks**
When application code passes PyJWT's `algorithms`, `options` or `verify` arguments positionally, the sink patterns match only keyword arguments, so positional calls that disable signature verification or use a token-selected algorithm pass without a finding.
Extend the PyJWT and TLS rules to recognize the supported positional forms of these verification arguments.
Also at `.semgrep/cloud-registry.yml:31-33`.
</issue_to_address>
### Comment 2
<location path=".semgrep/cloud-registry.yml" line_range="67-68" />
<code_context>
+ JWTs must be verified with a fixed list of signature algorithms: not
+ with `none`, and not with the algorithm that the token's header names
+ # Taint mode, so that values reach `algorithms` also through variables
+ # (e.g., `alg = header["alg"]`) and collections. Taint is tracked within
+ # a function only (not into helpers, nor from module constants into
+ # functions). An `alg` from the header that is checked against an
+ # allowlist is still reported: pass the allowlist itself instead
</code_context>
<issue_to_address>
**Cross-function values evade taint checks**
When an algorithm comes from a module constant or helper, including an unverified header parsed in another function, semgrep's taint tracking stops at function boundaries and does not track module constants into functions, so the unsafe algorithm reaches the decode sink without a finding.
Add rule coverage for unsafe algorithm values that flow through helpers or module constants into decode calls.
Also at `.semgrep/cloud-registry.yml:83`.
</issue_to_address>
### Comment 3
<location path=".semgrep/cloud-registry.yml" line_range="78" />
<code_context>
+ taint_assume_safe_indexes: true
+ pattern-sources:
+ # The unverified header, and anything taken from it
+ - pattern: jwt.get_unverified_header(...)
+ # Any string literal `none`, in any case, also where it is removed from
+ # a set (e.g., `algorithms - {"none"}`, reported too): an exception
</code_context>
<issue_to_address>
**PyJWT instance headers evade taint checks**
When a caller reads a token header through a `PyJWT` instance and uses its `alg` in a decode call, the source pattern matches only `jwt.get_unverified_header(...)`, so the instance method does not taint the returned header and the decode passes without a finding.
Extend the source pattern to recognize `get_unverified_header(...)` calls on `PyJWT` instances.
</issue_to_address>
### Comment 4
<location path=".semgrep/cloud-registry.yml" line_range="136-137" />
<code_context>
+ # requests skips the check for any falsy `verify`; `None` in a call
+ # means the session's default, but as the session's setting, no check
+ pattern-either:
+ - patterns:
+ - pattern: $SESSION.verify = $OFF
+ - metavariable-pattern:
+ metavariable: $OFF
+ pattern-either:
+ - pattern: "False"
+ - pattern: "None"
+ - pattern: "0"
+ - pattern: "0.0"
+ - pattern: '""'
+ - pattern: "[]"
+ - pattern: "{}"
+ - patterns:
+ - pattern-either:
+ # Any function of the requests module
+ - pattern: requests.$FUNCTION(..., verify=$OFF, ...)
+ - patterns:
+ - pattern: $X.$METHOD(..., verify=$OFF, ...)
+ # The request methods of requests' sessions (and of the
+ # module, and of similar clients)
</code_context>
<issue_to_address>
**Unpacked TLS settings bypass scan**
When application code passes a mapping containing `verify=False` or another disabled value through `**kwargs` to a request call, when application code puts `verify=False` in a mapping and passes it with `**kwargs`, neither pattern matches the unpacked argument, so the request disables TLS verification without a finding and accepts responses from a man-in-the-middle.
Add coverage for unpacked keyword mappings, including mappings assigned to variables, or otherwise reject unverified request options at the call boundary.
</issue_to_address>
### Comment 5
<location path=".semgrep/cloud-registry.yml" line_range="36-37" />
<code_context>
+ - pattern: "$JWT.$DECODE(..., verify=$OFF, ...)"
+ - patterns:
+ - pattern-either:
+ - pattern-inside: |
+ $OPTIONS = {..., "verify_signature": $OFF, ...}
+ ...
+ - pattern-inside: |
</code_context>
<issue_to_address>
**Mutated JWT options bypass detection**
When code adds or updates the verification option after creating the dictionary, the rule recognizes option dictionaries only when the falsy setting is present in the dictionary’s assignment, so building `options = {}` and then setting `options["verify_signature"] = False` lets `jwt.decode(..., options=options)` pass without a finding.
Track assignments to `options["verify_signature"]` and equivalent updates through to the decode call, and add a mutation test.
</issue_to_address>
### Comment 6
<location path=".semgrep/cloud-registry.yml" line_range="53-54" />
<code_context>
+ - pattern: "0"
+ - pattern: "0.0"
+ - pattern: '""'
+ - pattern: "[]"
+ - pattern: "{}"
+ # `decode()` and `decode_complete()` of `jwt` and `jwt.PyJWT()` (also
+ # imported under other names)
</code_context>
<issue_to_address>
**Empty tuples evade verification checks**
When a caller supplies an empty tuple as a TLS or JWT verification setting, the rules enumerate other falsy literals but omit `()`, so Requests and PyJWT treat the setting as false and the insecure call passes without a finding.
Add the empty tuple to each relevant list of falsy verification values.
Also at `.semgrep/cloud-registry.yml:124-131`, `.semgrep/cloud-registry.yml:146-151`.
</issue_to_address>
### Comment 7
<location path=".ast-grep/rules/root-logger-call.yml" line_range="10" />
<code_context>
+ that log messages can be configured by logger name.
+rule:
+ any:
+ - pattern: logging.$METHOD($$$ARGS)
+ - pattern: logging.root.$METHOD($$$ARGS)
+ - pattern: logging.getLogger().$METHOD($$$ARGS)
</code_context>
<issue_to_address>
**Aliased root-logger calls evade checks**
When code imports a logging function directly, aliases the logging module, or stores the root logger in a variable, the rule matches direct `logging` spellings and inline root-logger calls, so equivalent calls through these aliases pass without a finding.
Extend the rule to recognize imported functions, aliased modules and calls through variables holding the root logger.
Also at `.ast-grep/rules/root-logger-call.yml:12`.
</issue_to_address>
### Comment 8
<location path=".semgrep/cloud-registry.py" line_range="17" />
<code_context>
jwt.decode(TOKEN, options={"verify_signature": False})
</code_context>
<issue_to_address>
**security (python.jwt.security.unverified-jwt-decode):** Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified.
```suggestion
jwt.decode(TOKEN, options={"verify_signature": True})
```
*Source: opengrep*
</issue_to_address>
### Comment 9
<location path=".semgrep/cloud-registry.py" line_range="19" />
<code_context>
jwt.decode(TOKEN, KEY, algorithms=["RS256"], options={"verify_signature": False})
</code_context>
<issue_to_address>
**security (python.jwt.security.unverified-jwt-decode):** Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified.
```suggestion
jwt.decode(TOKEN, KEY, algorithms=["RS256"], options={"verify_signature": True})
```
*Source: opengrep*
</issue_to_address>
### Comment 10
<location path=".semgrep/cloud-registry.py" line_range="41" />
<code_context>
jwt_decode(TOKEN, options={"verify_signature": False})
</code_context>
<issue_to_address>
**security (python.jwt.security.unverified-jwt-decode):** Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified.
```suggestion
jwt_decode(TOKEN, options={"verify_signature": True})
```
*Source: opengrep*
</issue_to_address>
### Comment 11
<location path=".semgrep/cloud-registry.py" line_range="43" />
<code_context>
pyjwt.decode(TOKEN, options={"verify_signature": False})
</code_context>
<issue_to_address>
**security (python.jwt.security.unverified-jwt-decode):** Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified.
```suggestion
pyjwt.decode(TOKEN, options={"verify_signature": True})
```
*Source: opengrep*
</issue_to_address>
### Comment 12
<location path=".semgrep/cloud-registry.py" line_range="44" />
<code_context>
unverified = {"verify_signature": False}
</code_context>
<issue_to_address>
**security (python.jwt.security.unverified-jwt-decode):** Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified.
```suggestion
unverified = {"verify_signature": True}
```
*Source: opengrep*
</issue_to_address>
### Comment 13
<location path=".semgrep/cloud-registry.py" line_range="76" />
<code_context>
jwt.decode(TOKEN, options={"verify_signature": VERIFY})
</code_context>
<issue_to_address>
**security (python.jwt.security.unverified-jwt-decode):** Detected JWT token decoded with 'verify=False'. This bypasses any integrity checks for the token which means the token could be tampered with by malicious actors. Ensure that the JWT token is verified.
```suggestion
jwt.decode(TOKEN, options={"verify_signature": True})
```
*Source: opengrep*
</issue_to_address>
### Comment 14
<location path=".semgrep/cloud-registry.py" line_range="170" />
<code_context>
yaml.unsafe_load("a: 1")
</code_context>
<issue_to_address>
**security (python.lang.security.deserialization.avoid-pyyaml-load):** Detected a possible YAML deserialization vulnerability. `yaml.unsafe_load`, `yaml.Loader`, `yaml.CLoader`, and `yaml.UnsafeLoader` are all known to be unsafe methods of deserializing YAML. An attacker with control over the YAML input could create special YAML input that allows the attacker to run arbitrary Python code. This would allow the attacker to steal files, download and install malware, or otherwise take over the machine. Use `yaml.safe_load` or `yaml.SafeLoader` instead.
```suggestion
yaml.safe_load("a: 1")
```
*Source: opengrep*
</issue_to_address>
### Comment 15
<location path=".semgrep/cloud-registry.py" line_range="180" />
<code_context>
yaml.load_all("a: 1", Loader=yaml.UnsafeLoader)
</code_context>
<issue_to_address>
**security (python.lang.security.deserialization.avoid-pyyaml-load):** Detected a possible YAML deserialization vulnerability. `yaml.unsafe_load`, `yaml.Loader`, `yaml.CLoader`, and `yaml.UnsafeLoader` are all known to be unsafe methods of deserializing YAML. An attacker with control over the YAML input could create special YAML input that allows the attacker to run arbitrary Python code. This would allow the attacker to steal files, download and install malware, or otherwise take over the machine. Use `yaml.safe_load` or `yaml.SafeLoader` instead.
```suggestion
yaml.load_all("a: 1", Loader=yaml.UnsafeLoader)
```
*Source: opengrep*
</issue_to_address>
### Comment 16
<location path=".semgrep/cloud-registry.py" line_range="184" />
<code_context>
yaml.load_all("a: 1", Loader=yaml.Loader)
</code_context>
<issue_to_address>
**security (python.lang.security.deserialization.avoid-pyyaml-load):** Detected a possible YAML deserialization vulnerability. `yaml.unsafe_load`, `yaml.Loader`, `yaml.CLoader`, and `yaml.UnsafeLoader` are all known to be unsafe methods of deserializing YAML. An attacker with control over the YAML input could create special YAML input that allows the attacker to run arbitrary Python code. This would allow the attacker to steal files, download and install malware, or otherwise take over the machine. Use `yaml.safe_load` or `yaml.SafeLoader` instead.
```suggestion
yaml.load_all("a: 1", Loader=yaml.Loader)
```
*Source: opengrep*
</issue_to_address>Sourcery assessment
Approval pending. 16 findings to address first.
Blocking findings: .semgrep/cloud-registry.yml:86, .semgrep/cloud-registry.yml:68, .semgrep/cloud-registry.yml:78, .semgrep/cloud-registry.yml:137, .semgrep/cloud-registry.yml:37, and 11 more
Summary
Takes over FOCA's shared semgrep rules as widened in elixir-cloud-aai/foca#784, identical apart from
paths(app config and chart), with their tests (.semgrep/cloud-registry.py,.semgrep/cloud-registry.test.yaml), and runs the rule tests in pre-commit (semgrep-testhook, as in proWES and trs-filer):tls-verification-disabled(new): disabled certificate verification, also in calls on sessions (session.get(url, verify=False)), which ruff's S501 missesjwt-decode-without-verification: any falsyverify_signature/verify(alsoNoneand constants), on any PyJWT receiver,decode_complete(), and assigned optionsjwt-decode-unsafe-algorithms(new, taint mode):noneor the token header'salgreachingalgorithms, also through variablesyaml-unsafe-load(new), andflask-debug-enablednow also matchesdebug: 1Ports the ast-grep rules widened in elixir-cloud-aai/prowes#147:
string-status-code(returned tuples in parentheses, prefixed strings) and the newroot-logger-call, with tests. The development guide mentions the rule tests and the root logger rule.The rules find nothing in the code.
Closes #413
Part of elixir-cloud-aai/foca#783
Verification
cd .semgrep && semgrep --test .: 5/5 passed.ast-grep test --skip-snapshot-tests: 4/4 passed;ast-grep scan: no findings.pre-commit run --all-files: ruff, the rule tests and the file checks pass; thesemgrephook fails locally only because semgrep-core can't allocate io_uring queues when pre-commit runs it in parallel (the same scan run serially passes), and actionlint lacks a local shellcheck. CI covers both..semgrep/,.ast-grep/, the pre-commit config and docs change; locally, tests that need the library chart fail withouthelm dependency build(unrelated to this change). CI runs the suite.paths(scoping checked in a scratch repo), tests equal FOCA's apart from the file name and import order, no narrowing of the earlier rules.CI passedincluded.Sourcery
Sourcery's check may fail on the deliberately insecure rule-test fixtures in
.semgrep/(accepted before for trs-filer #149 and proWES #147);.sourcery.yamlalready ignores them.🤖 Generated with Claude Code
Summary by Sourcery
Strengthen static analysis coverage for insecure TLS, JWT, YAML, logging, Flask configuration, and HTTP status-code patterns.
New Features:
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: