fix(code_safety): demote unwrap_or(0) off critical severity (false positive)#522
Merged
Merged
Conversation
`.unwrap_or(0)` is the panic-free, idiomatic-safe form -- it cannot panic, yet :unwrap_dangerous_default rated it :critical while rating `.unwrap()` (which does panic) only :high, inverting the risk order. Demote :critical -> :low, switch CWE-754 -> CWE-252 (None/Err collapsed to a default, not improper exception handling), and reword to drop the panic framing. Surfaced by two false positives on hyperpolymath/affinescript#651 (both correct LSP defaults). Addresses the rule half of #521; the reporting-gap half remains. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UXXpaoiATzxcn3kW3eTM26
🔍 Hypatia Security ScanFindings: 42 issues detected
View findings[
{
"reason": "Repository has 6 non-main remote branch(es). Policy: single main branch only.",
"type": "GS007",
"file": ".",
"action": "delete_remote_branches",
"rule_module": "git_state",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "src/ui/gossamer/README.adoc",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "scripts/ci-tools/Cargo.toml",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "scripts/bench-tools/Cargo.toml",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "ffi/zig/README.adoc",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "docs/reports/audit/audit-2026-04-15-post.md",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "docs/integration/github-registry.adoc",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "docs/integration/github-registry.adoc",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "docs/integration/a2ml-k9.md",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
},
{
"reason": "Code scanning (Hypatia): hypatia/structural_drift/SD022 -- Hypatia structural_drift: SD022 -- 19 day(s) old",
"type": "CSA001",
"file": "docs/architecture/system-integration.md",
"action": "review",
"rule_module": "code_scanning_alerts",
"severity": "medium"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
lib/rules/code_safety.exrated:unwrap_dangerous_default(~r/\.unwrap_or\(0\)/) as:critical/ CWE-754. But.unwrap_or(0)is the panic-free, idiomatic-safe form — it's the fix for.unwrap()and cannot panic. The same module rates.unwrap()(which does panic) only:high, so the safe form outranked the unsafe one.This change:
:critical→:low(now correctly below:unwrap_without_check's:high),CWE-754→CWE-252(None/Err collapsed to a default — not improper exception handling, sinceunwrap_oris the handling),Why
Surfaced while triaging the Hypatia scan on
hyperpolymath/affinescript#651: the two reportedcriticalfindings were both.unwrap_or(0)in correct LSP code (tools/affinescript-lsp/src/{main.rs:155,handlers.rs:575}) — a start-of-line word-boundary default, and a protocol-version default that is immediately range-checked. Both are false positives; the miscalibrated rule is the cause.Scope
Addresses the rule half of #521. The other half (critical findings counted but never listed in the scan comment/artifact/log) is a separate change in the reporting path and remains tracked in #521.
Tests
No test asserts this rule's severity (
code_safety_test.exsonly references:unwrap_without_check), so the change is test-safe. The pattern/id are unchanged, so.unwrap_or(0)is still detected — just at:low.Refs: #521 ·
hyperpolymath/affinescript#651·hyperpolymath/affinescript#655🤖 Generated with Claude Code
Generated by Claude Code