Skip to content

chore: drive CodeQL to zero and keep it there - #391

Merged
DeepDiver1975 merged 1 commit into
refactor/path-joinfrom
chore/codeql-zero
Sep 17, 2026
Merged

DeepDiver1975 merged 1 commit into
refactor/path-joinfrom
chore/codeql-zero

Conversation

@DeepDiver1975

Copy link
Copy Markdown
Contributor

Stacked on #390. Base is refactor/path-join; it becomes main once #390 merges. Review #390 first.

Why

main carried 223 open CodeQL alerts. Between them they had no security severity at all — every one came from the quality half of the security-and-quality suite.

The reason they piled up is duplication. The build already runs the .NET analyzers at AnalysisMode=All plus StyleCop with TreatWarningsAsErrors. But CodeQL cannot see a per-member [SuppressMessage] or an .editorconfig severity, so every decision this repo had already made and written down came back as a permanently open alert that nobody could close. And CodeQL gates nothing — main's required checks are build-test ×2, changelog entry and DCO — so they accumulated in silence.

#390 cleared 144 of them by switching to Path.Join. This PR handles the remaining 79.

The one real defect

Seven dead local assignments, left over from earlier refactors — including one in EqualWidthWrapPanel's arrange pass, dead since the arrange path moved to ColumnEdge(…).

They survived an otherwise maximally strict build because IDE0059 ships at suggestion severity, below the threshold TreatWarningsAsErrors acts on. .editorconfig now raises it to warning. Verified rather than assumed — reintroducing the dead local fails the build:

EqualWidthWrapPanel.cs(91,13): error IDE0059: Unnecessary assignment of a value to 'itemWidth'
Build FAILED.

Note the identical line in MeasureOverride is used and was left alone.

The exclusions — nine queries, each against the rule that duplicates it

New .github/codeql/codeql-config.yml. No query carrying a security severity is excluded. Every entry names the rule the build already governs it by:

Query Already governed by
cs/catch-of-all-exceptions (21) CA1031, on as an error — all 19 sites carry a per-member [SuppressMessage] naming where the failure surfaces
cs/local-not-disposed, cs/dispose-not-called-on-throw (30) CA2000/CA2213, already = none under [tests/**/*.cs] with a written rationale
cs/xmldoc/missing-summary (4) SA1600–SA1649 disabled, CS1591 in NoWarn
cs/unmanaged-code, cs/call-to-unmanaged-code (2) CA5392, on and satisfied — the winmm.dll P/Invoke already carries [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
cs/linq/missed-where, cs/linq/missed-select (11) no Roslyn equivalent; style-only
cs/missed-ternary-operator (1) fires only in xunit's generated obj/ entry point

Two of these deserve saying out loud, because "suppress the generic catch warning" normally is the lazy answer:

  • SerialAudioQueue catches broadly on purpose — "a misbehaving cue must not stop the queue from serving the next one." This is the Rückzugsalarm path in an incident log running live in an ELW. Narrowing it would let one bad cue silence every later alarm.
  • TasksViewModel's flagged loop mutates the fire-once alarm-dedupe set inside the loop condition. Applying cs/linq/missed-where would move that into a lazily-evaluated .Where(…) and change when — or whether — the Aufgabe-fällig alarm sounds. The "fix" would be the bug.

paths-ignore is not an option here: GitHub restricts paths/paths-ignore to interpreted languages or build-mode: none, and this is C# under build-mode: manual. Rule id is the only lever, which is why the generated-code alert is handled as a query exclusion.

Honesty repair

.bestpractices.json asserted "There are no outstanding CodeQL alerts; the first full run on the default branch reported none." That was committed in #370 and is a public OpenSSF Best Practices claim. It now describes the policy — fix in code by default, exclude only duplicated rules, never a security query, dismiss only site-specific false positives — instead of asserting a clean first run.

Keeping it at zero

  • AGENTS.md gains a "Static analysis" section: Path.Join over Path.Combine, a justified [SuppressMessage] on every catch (Exception), no dead locals, and the three-step procedure for a new alert.
  • Follow-up, not in this PR: a code_scanning ruleset rule so a PR introducing a new alert cannot merge. It has to be added after this lands and a fresh main scan reads zero, or it would block its own enabling PR.

Remaining three alerts

Handled by dismissal after merge, because they are site-specific rather than rule-wide:

  • cs/constant-condition ×2 — false positive. CodeQL mis-models is false on bool?; Dwelling.KeyAvailable is bool? and null is the meaningful "Schlüssel unbekannt" third state rendering —. Collapsing the ternary would print "nein" for unknown keys, which in a CO-Messprotokoll is a wrong operational statement.
  • cs/complex-block ×1 — won't fix. IncidentRepository.Save is long but flat: one INSERT block per table across 16 tables in one transaction, which is what makes the table list auditable at a glance.

Verification

  • dotnet build LageBuch.Desktop.slnf -c Release → 0 warnings, 0 errors, with IDE0059 now in force
  • dotnet test LageBuch.Desktop.slnf -c Release → 1324 passed, 0 failed, 1 pre-existing skip
  • dotnet format whitespace / style --verify-no-changes → clean
  • Both YAML files parse; .bestpractices.json parses (140 keys)

No screenshots: deleting an unread local in ArrangeOverride cannot change a rendered pixel, and the 178-test acceptance render suite passing unchanged demonstrates that rather than asserting it.

🤖 Generated with Claude Code

The 223 open alerts on main carried no security severity between them:
every one came from the quality half of the security-and-quality suite,
and most were CodeQL re-reporting a decision the build had already made.
The .NET analyzers run at AnalysisMode=All with TreatWarningsAsErrors,
but CodeQL cannot see a per-member [SuppressMessage] or an .editorconfig
severity, so each such decision surfaced again as a permanently open
alert nobody could close.

Record those decisions where CodeQL can see them, in a config file whose
every exclusion names the CA or SA rule that already governs the same
code, and fix what was genuinely wrong:

- Seven dead locals, the one real defect the suite found. IDE0059 ships
  at suggestion severity, below the threshold TreatWarningsAsErrors acts
  on, which is how they accumulated in an otherwise maximally strict
  build. Raising it to warning makes the next one a build error --
  verified by reintroducing one and watching the build fail.
- .github/codeql/codeql-config.yml excludes nine queries, none carrying
  a security severity, each against the rule that duplicates it: CA1031
  for the generic catches, CA2000 for test-local disposal, the StyleCop
  documentation family, CA5392 for the winmm P/Invoke that already
  carries DefaultDllImportSearchPaths, plus LINQ style suggestions with
  no Roslyn equivalent and xunit's generated entry point.
- .bestpractices.json claimed there were no outstanding alerts. It now
  describes the policy instead of asserting a clean first run.
- AGENTS.md gains a "Static analysis" section: the code rules, and what
  to do when a new alert appears -- fix it, or exclude it by id with a
  written rationale, and dismiss only a site-specific false positive.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975
DeepDiver1975 merged commit 480cf9e into refactor/path-join Sep 17, 2026
4 checks passed
@DeepDiver1975
DeepDiver1975 deleted the chore/codeql-zero branch September 17, 2026 21:39
DeepDiver1975 added a commit that referenced this pull request Sep 17, 2026
The 223 open alerts on main carried no security severity between them:
every one came from the quality half of the security-and-quality suite,
and most were CodeQL re-reporting a decision the build had already made.
The .NET analyzers run at AnalysisMode=All with TreatWarningsAsErrors,
but CodeQL cannot see a per-member [SuppressMessage] or an .editorconfig
severity, so each such decision surfaced again as a permanently open
alert nobody could close.

Record those decisions where CodeQL can see them, in a config file whose
every exclusion names the CA or SA rule that already governs the same
code, and fix what was genuinely wrong:

- Seven dead locals, the one real defect the suite found. IDE0059 ships
  at suggestion severity, below the threshold TreatWarningsAsErrors acts
  on, which is how they accumulated in an otherwise maximally strict
  build. Raising it to warning makes the next one a build error --
  verified by reintroducing one and watching the build fail.
- .github/codeql/codeql-config.yml excludes nine queries, none carrying
  a security severity, each against the rule that duplicates it: CA1031
  for the generic catches, CA2000 for test-local disposal, the StyleCop
  documentation family, CA5392 for the winmm P/Invoke that already
  carries DefaultDllImportSearchPaths, plus LINQ style suggestions with
  no Roslyn equivalent and xunit's generated entry point.
- .bestpractices.json claimed there were no outstanding alerts. It now
  describes the policy instead of asserting a clean first run.
- AGENTS.md gains a "Static analysis" section: the code rules, and what
  to do when a new alert appears -- fix it, or exclude it by id with a
  written rationale, and dismiss only a site-specific false positive.

Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
DeepDiver1975 added a commit that referenced this pull request Sep 17, 2026
* refactor: join paths with Path.Join instead of Path.Combine

Path.Combine silently discards every earlier argument once a later one
turns out to be rooted, so a name that ever slipped past sanitisation
could resolve outside the directory it was meant to land in. Path.Join
always concatenates, so the same slip stays contained.

Behaviour is unchanged at all 163 call sites: every later argument here
is relative, and untrusted names still pass IncidentFile.SanitizeFileName
or SafeFileName.Sanitize before they reach a join. This is defence in
depth, and it clears the 144 cs/path-combine CodeQL alerts, which fired
on 100% of the call sites rather than on any specific one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>

* chore: drive CodeQL to zero and keep it there (#391)

The 223 open alerts on main carried no security severity between them:
every one came from the quality half of the security-and-quality suite,
and most were CodeQL re-reporting a decision the build had already made.
The .NET analyzers run at AnalysisMode=All with TreatWarningsAsErrors,
but CodeQL cannot see a per-member [SuppressMessage] or an .editorconfig
severity, so each such decision surfaced again as a permanently open
alert nobody could close.

Record those decisions where CodeQL can see them, in a config file whose
every exclusion names the CA or SA rule that already governs the same
code, and fix what was genuinely wrong:

- Seven dead locals, the one real defect the suite found. IDE0059 ships
  at suggestion severity, below the threshold TreatWarningsAsErrors acts
  on, which is how they accumulated in an otherwise maximally strict
  build. Raising it to warning makes the next one a build error --
  verified by reintroducing one and watching the build fail.
- .github/codeql/codeql-config.yml excludes nine queries, none carrying
  a security severity, each against the rule that duplicates it: CA1031
  for the generic catches, CA2000 for test-local disposal, the StyleCop
  documentation family, CA5392 for the winmm P/Invoke that already
  carries DefaultDllImportSearchPaths, plus LINQ style suggestions with
  no Roslyn equivalent and xunit's generated entry point.
- .bestpractices.json claimed there were no outstanding alerts. It now
  describes the policy instead of asserting a clean first run.
- AGENTS.md gains a "Static analysis" section: the code rules, and what
  to do when a new alert appears -- fix it, or exclude it by id with a
  written rationale, and dismiss only a site-specific false positive.

Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant