Repository navigation
fix: catch disabled TLS checks in session calls - #499
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 GuideConfigurationAdd and broaden the Semgrep security rules for Flask debug mode, JWT verification and algorithms, unsafe YAML loading, and disabled TLS verification, including falsy values and session calls.
Add the root-logger-call ast-grep rule and broaden string-status-code detection to cover parenthesized tuples and prefixed strings.
Configure pre-commit to run Semgrep rule tests and exclude their intentionally insecure fixtures from the regular Semgrep scan.
DocumentationDocument the shared Semgrep rules, ast-grep checks, and their rule tests in the development guide.
TestsAdd Semgrep fixtures covering the security rules, including disabled TLS checks on session calls and safe cases.
Add Semgrep fixtures for enabled and disabled Flask debug configuration values.
Add ast-grep fixtures for root logger calls.
Extend ast-grep fixtures for string status codes, including parenthesized return tuples.
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 #499 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 35 35
Lines 3239 3239
=========================================
Hits 3239 3239 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit d97da34 #500 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 6 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/pro-tes.yml" line_range="31" />
<code_context>
- pattern-either:
- - pattern: 'jwt.decode(..., options={..., "verify_signature": False, ...}, ...)'
- - pattern: "jwt.decode(..., verify=False, ...)"
+ - pattern: '$JWT.$DECODE(..., options={..., "verify_signature": $OFF, ...}, ...)'
+ - pattern: "$JWT.$DECODE(..., options=dict(..., verify_signature=$OFF, ...), ...)"
+ - pattern: "$JWT.$DECODE(..., verify=$OFF, ...)"
</code_context>
<issue_to_address>
**Unsafe decoding calls go unreported**
When a caller passes security-sensitive arguments positionally or through expanded keyword arguments, the JWT and TLS rules match keyword arguments but miss PyJWT’s positional `algorithms` and `options` arguments and unsafe values supplied through `**kwargs`, so decoding can skip signature verification or accept an unsafe algorithm without a finding. Add patterns that recognize these argument forms.
Extend the rules to inspect positional arguments and expanded keyword arguments for unsafe values.
Also at `.semgrep/pro-tes.yml:86`, `.semgrep/pro-tes.yml:135-137`.
</issue_to_address>
### Comment 2
<location path=".semgrep/pro-tes.yml" line_range="34-42" />
<code_context>
+ - pattern: '$JWT.$DECODE(..., options={..., "verify_signature": $OFF, ...}, ...)'
+ - pattern: "$JWT.$DECODE(..., options=dict(..., verify_signature=$OFF, ...), ...)"
+ - pattern: "$JWT.$DECODE(..., verify=$OFF, ...)"
+ - patterns:
+ - pattern-either:
+ - pattern-inside: |
+ $OPTIONS = {..., "verify_signature": $OFF, ...}
+ ...
+ - pattern-inside: |
+ $OPTIONS = dict(..., verify_signature=$OFF, ...)
+ ...
+ - pattern: $JWT.$DECODE(..., options=$OPTIONS, ...)
+ # Falsy values, which PyJWT treats alike; patterns rather than a regex,
+ # so that constants assigned before (e.g., `VERIFY = False`) match too
</code_context>
<issue_to_address>
**Mutated JWT options evade detection**
When a caller disables verification by mutating an options dictionary before decoding, a caller that creates an options dictionary and then assigns `options["verify_signature"] = False` does not match either supported dictionary-literal assignment pattern. The decode call is therefore unreported and accepts tokens without signature verification.
Add coverage for subscript assignments that reach a decode call, or use taint analysis for the verification option.
</issue_to_address>
### Comment 3
<location path=".semgrep/pro-tes.yml" line_range="54" />
<code_context>
+ - 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>
**Falsy verification values go unreported**
When an empty tuple or set is supplied as a verification value, the JWT and TLS rules omit these falsy values, so PyJWT or Requests disables signature or certificate verification without producing a finding. Include empty tuples and sets in the falsy-value patterns.
Add empty tuple and set forms to the falsy-value patterns.
Also at `.semgrep/pro-tes.yml:124-131`, `.semgrep/pro-tes.yml:145-151`.
</issue_to_address>
### Comment 4
<location path=".semgrep/pro-tes.yml" line_range="137" />
<code_context>
+ # 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>
**Positional TLS bypasses go undetected**
When a caller supplies `verify=False` positionally to `Session.request`, a `Session.request` call that passes `verify=False` in its positional `verify` slot does not match the keyword-only pattern, so Semgrep reports no finding and the disabled certificate check passes this guard.
Add a pattern for the positional `verify` argument of `Session.request` and a rule test for it.
</issue_to_address>
### Comment 5
<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>
**Imported calls bypass security checks**
When code uses a module alias or calls a directly imported function, the root-logger, JWT, and YAML rules match qualified module names but miss aliased or directly imported calls, so these calls produce no finding. Extend the relevant patterns to recognize aliases and imported function names.
Update the relevant rules to recognize aliased modules and directly imported functions.
Also at `.semgrep/pro-tes.yml:31`, `.semgrep/pro-tes.yml:78`, `.semgrep/pro-tes.yml:97-102`.
</issue_to_address>
### Comment 6
<location path=".semgrep/pro-tes.yml" line_range="22" />
<code_context>
- "/pro_tes/config.yaml"
- "/deployment/**/*.yaml"
- pattern-regex: (?im)^\s*debug:\s*['"]?(true|yes|on)['"]?\s*(#.*)?$
+ pattern-regex: (?im)^\s*debug:\s*['"]?(true|yes|on|1)['"]?\s*(#.*)?$
- id: jwt-decode-without-verification
languages: [python]
</code_context>
<issue_to_address>
**Truthy debug values go unreported**
When a scoped configuration sets `debug` to a nonzero number other than 1, the debug regex matches only `1`, so values such as `2` and `1.0` enable debug mode without producing a finding. Extend the regex to match nonzero numeric values.
Update the debug regex to recognize nonzero numeric values.
</issue_to_address>
### Comment 7
<location path=".semgrep/pro-tes.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 8
<location path=".semgrep/pro-tes.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 9
<location path=".semgrep/pro-tes.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 10
<location path=".semgrep/pro-tes.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 11
<location path=".semgrep/pro-tes.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 12
<location path=".semgrep/pro-tes.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 13
<location path=".semgrep/pro-tes.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 14
<location path=".semgrep/pro-tes.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 15
<location path=".semgrep/pro-tes.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. 15 findings to address first.
Blocking findings: .semgrep/pro-tes.yml:31, .semgrep/pro-tes.yml:42, .semgrep/pro-tes.yml:54, .semgrep/pro-tes.yml:137, .ast-grep/rules/root-logger-call.yml:10, and 10 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/pro-tes.py,.semgrep/pro-tes.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 #500
Part of elixir-cloud-aai/foca#783
Verification
cd .semgrep && semgrep --test .: 5/5 passed.ast-grep test --skip-snapshot-tests: 5/5 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 response patterns.
New Features:
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: