mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-25 06:35:21 +00:00
docs(lean): model the merge of error results as GH-25
Add the merge model for error-status results and the ledger row. One error result with one clean result reads clean, all errors read error, and an error never hides a finding.
This commit is contained in:
+16
-1
@@ -29,6 +29,7 @@ Currency: `sh lean4/scripts/check_currency.sh origin/main`.
|
||||
| GH-22 | dashboard API | an OIDC-logged-in browser can call `/api` with a long URL; the proxy hop neither forwards session cookies nor exceeds the read buffer | availability | medium (every `/api` call returned 431 for OIDC users) | not modelled (header size, no decision logic) / `TestLargeRequestHeadersAreAccepted`, `TestReadBufferSizeIsConfigurable`, `scripts/check_frontend_cookie_strip.sh` | 536f35a |
|
||||
| GH-23 | PyPI sidecar | pip's PEP 658 request (`<link>.metadata`, suffix on `original_url`) is served as its wheel's sidecar; another file's sidecar is still refused | correctness (pip install failed with 400) | medium (every pip install through the proxy) | `Access.pip_form_keeps_key_binding`, `pip_sidecar_of_other_file_rejected`, `pip_sidecar_of_same_file_accepted` / `TestPipSidecarFormIsStreamed`, `TestHandlePackageFile_OriginalURLFilenameBound` | 501bf1a |
|
||||
| GH-24 | rescan | with `security.rescan_interval` set, artifacts whose scan never completed are scanned and old results refreshed | correctness (scans lost to a restart stayed unscanned; new CVEs never picked up) | medium | not modelled (worker wiring) / `TestWorkersStartTheRescanWorker` | 378b873 |
|
||||
| GH-25 | scanners | an error result from one scanner is left out of the merge, so the row reads error only when every scanner failed; grype, npm-audit, govulncheck and pip-audit give correct results with the scanner image tool versions | correctness (false error, false clean) | high (grype, npm-audit and pip-audit failed on every package; govulncheck and a bare-archive grype scan read vulnerable packages clean) | `Security.old_error_poisons_clean`, `error_and_clean_reads_clean`, `all_error_reads_error`, `merged_not_error_when_one_ran` / `TestScanPackage_ErrorResultPlusCleanReadsClean`, `TestScanPackage_AllErrorResultsReadError`, `TestScanPackage_InfrastructureErrorResultsCountAsInfrastructure`, `TestScanMapsRealOutput`, `TestParseKeepsBothViaShapes`, `TestScanReadsPrettyPrintedFindings`, `TestScanAuditsTheReleaseFromARequirement` | 3731ca0 |
|
||||
|
||||
### Exploit paths and reach
|
||||
|
||||
@@ -67,6 +68,20 @@ Currency: `sh lean4/scripts/check_currency.sh origin/main`.
|
||||
local storage. A remote blob is copied to a temp file for the scan and removed after it. Test: `TestRescanWorkerScansRemoteStorage`.
|
||||
- **GH-22.** Frontend nginx dropped the `Cookie` header on `/api/` and `/ws` (the backend reads none; keys travel in `Authorization` / `X-API-Key`).
|
||||
The server read buffer is `server.read_buffer_size`, default 16384 (Fiber's default is 8192): a long Referer or `Authorization` no longer gets 431.
|
||||
- **GH-25.** `scan` treats an error-status result like a returned error: it is left out of the merge and counted as an
|
||||
infrastructure failure (`infrastructure_error` in its details, set on a deadline or an unreachable network) or another failure.
|
||||
Before, one such result made the merged row an error and `evaluateScan` blocked the package even with `fail_closed: false`.
|
||||
Defects found by running the published scanner image (grype 0.121.2, npm 11.12.1, govulncheck 1.9.0, pip-audit 2.10.1,
|
||||
go 1.26), each with a fixture of real output under the scanner's `testdata/`:
|
||||
grype: `source.target` is a string for file and purl sources, and a bare archive has nothing to catalog, so minimist 0.0.8 read clean;
|
||||
the scanner now passes a purl. npm audit: `via` is an array and `metadata.dependencies` an object in npm 11; the lockfile
|
||||
step resolved devDependencies (dayjs: 1567 packages, 142 findings, 28s) and `npm audit` cannot report the root package itself;
|
||||
the tarball is now installed into a wrapper project and audited with `--omit=dev` (under 1s). govulncheck: the JSON stream is
|
||||
indented, so the line parser read nothing, and govulncheck never reports the main module of the tree it scans (x/text 0.3.5
|
||||
read clean); the module is now a dependency of a wrapper module and scanned at module level. pip-audit: its positional
|
||||
argument is a project directory and `--pyproject` does not exist, so every scan failed; the release is audited from a pinned
|
||||
requirement, an advisory is listed once, and `skip_reason` is an error. trivy is not covered: it reads a bare npm archive
|
||||
as clean the same way grype did.
|
||||
- **GH-17 cleanup.** The per-handler `Access-Control-*` lines in `pkg/app/handlers*.go` are removed; `apiOriginGuard` is the only CORS
|
||||
source. `TestHandlersSetNoCORSHeaders` and `TestAPIResponsesNeverCarryWildcardOrigin` guard it.
|
||||
|
||||
@@ -78,7 +93,7 @@ Currency: `sh lean4/scripts/check_currency.sh origin/main`.
|
||||
| GH-11 | cache hit | the stored SHA-256 is not re-verified on read | by-design | `Put` verifies the stream it just hashed; no doc promises read-side integrity. A check reads up to 2 GB per hit. Disk corruption is outside the proxy's threat model. |
|
||||
| GH-12 | idle purge | check and delete are two steps, so a request inside the window loses its blob | by-design | `Cache.purge_window_deletes_fresh_entry`. The consequence is a refetch; GH-07 covers the in-flight request. |
|
||||
| GH-13 | scan policy | with `fail_closed: false` a package whose scan keeps failing on infrastructure is served unscanned | by-design, accepted | See "Decision" below. |
|
||||
| GH-14 | scan merge | one scanner failing while another returns clean saves a clean result and schedules no retry | by-design | `Security.partial_failure_reads_clean`. `scan` handles only the all-failed case; redundancy across scanners is the intent. |
|
||||
| GH-14 | scan merge | one scanner failing while another returns clean saves a clean result and schedules no retry | by-design | `Security.error_and_clean_reads_clean` (a returned error and, since GH-25, an error-status result). `scan` handles only the all-failed case; redundancy across scanners is the intent. |
|
||||
| GH-16 | admin API | `requireAdmin` accepts the `bypasses:manage` permission and also guards key minting | tested-clean | Only the admin role holds that permission: `Access.admin_gate_implies_key_manager`. |
|
||||
|
||||
### Decision: `fail_closed: false` with recurring infrastructure errors
|
||||
|
||||
@@ -3,7 +3,7 @@ import Mathlib
|
||||
/-!
|
||||
# Security decision logic
|
||||
|
||||
Models `pkg/scanner/scanner.go` `CheckVulnerabilities`, `scan`, `mergeResults`, `scheduleRetry`,
|
||||
Models `pkg/scanner/scanner.go` `CheckVulnerabilities`, `scan`, `mergeResults`, `succeeded`, `scheduleRetry`,
|
||||
`pkg/metadata/gormstore/gormstore_v2.go` `GetActiveCVEBypasses`, and the scan gate in
|
||||
`pkg/cache/cache.go` `getOrFetch`. Severities are ranks (low 1 .. critical 4). Omits: the
|
||||
scanners themselves, threshold counters (`block_thresholds`), network.
|
||||
@@ -193,7 +193,7 @@ theorem npm_scan_keeps_cache_version (cacheVersion : String) :
|
||||
theorem file_name_is_not_release_version :
|
||||
"requests-2.19.0-py3-none-any.whl" ≠ "2.19.0" := by decide
|
||||
|
||||
/-! ### Merge: worst status wins, but a failed scanner leaves no trace -/
|
||||
/-! ### Merge: worst status wins among scanners that ran; a failed scanner leaves no trace -/
|
||||
|
||||
/-- ranks: clean 0, pending 1, error 2, vulnerable 3 (`mergeResults`). -/
|
||||
def mergeRank (xs : List ℕ) : ℕ := xs.foldr max 0
|
||||
@@ -207,8 +207,68 @@ theorem merge_dominates (xs : List ℕ) (x : ℕ) (h : x ∈ xs) : x ≤ mergeRa
|
||||
· exact le_max_left _ _
|
||||
· exact le_trans (ih h) (le_max_right _ _)
|
||||
|
||||
/-- Results exist only for scanners that returned; with one scanner failing and one clean, the
|
||||
merged status is clean and no retry is scheduled (`scan`: retry only when no scanner succeeded). -/
|
||||
theorem partial_failure_reads_clean : mergeRank [0] = 0 := by decide
|
||||
def errorRank : ℕ := 2
|
||||
|
||||
/-- Before GH-25 a scanner's error-status result took part in the merge, as the rank `errorRank`. -/
|
||||
def oldMerge (xs : List ℕ) : ℕ := mergeRank xs
|
||||
|
||||
/-- `scan` after GH-25: a scanner that returns an error-status result failed, like one that returns
|
||||
an error. Only results of scanners that ran are merged; with none left every scanner failed. -/
|
||||
def newMerge (xs : List ℕ) : ℕ :=
|
||||
if (xs.filter (· ≠ errorRank)).isEmpty then errorRank else mergeRank (xs.filter (· ≠ errorRank))
|
||||
|
||||
/-- GH-25: one scanner's error result turned a clean package into an error row. -/
|
||||
theorem old_error_poisons_clean : oldMerge [0, errorRank] = errorRank := by decide
|
||||
|
||||
theorem error_and_clean_reads_clean : newMerge [0, errorRank] = 0 := by decide
|
||||
|
||||
theorem error_never_hides_vulnerable : newMerge [errorRank, 3] = 3 := by decide
|
||||
|
||||
theorem all_error_reads_error (xs : List ℕ) (h : ∀ x ∈ xs, x = errorRank) : newMerge xs = errorRank := by
|
||||
have : xs.filter (· ≠ errorRank) = [] := by
|
||||
rw [List.filter_eq_nil_iff]
|
||||
intro x hx
|
||||
simp [h x hx]
|
||||
unfold newMerge
|
||||
rw [this]
|
||||
rfl
|
||||
|
||||
theorem error_result_ignored (xs : List ℕ) : newMerge (errorRank :: xs) = newMerge xs := by
|
||||
simp [newMerge]
|
||||
|
||||
theorem mergeRank_not_error (ys : List ℕ) (h : ∀ y ∈ ys, y ≠ errorRank) : mergeRank ys ≠ errorRank := by
|
||||
induction ys with
|
||||
| nil => simp [mergeRank, errorRank]
|
||||
| cons y ys ih =>
|
||||
simp only [mergeRank, List.foldr_cons]
|
||||
have hy : y ≠ errorRank := h y (List.mem_cons_self ..)
|
||||
have hys : mergeRank ys ≠ errorRank := ih (fun z hz => h z (List.mem_cons_of_mem _ hz))
|
||||
rcases max_choice y (ys.foldr max 0) with e | e
|
||||
· rw [e]; exact hy
|
||||
· rw [e]; exact hys
|
||||
|
||||
/-- With any scanner that ran, the merged status is not an error, so `fail_closed` never decides it. -/
|
||||
theorem merged_not_error_when_one_ran (xs : List ℕ) (h : ∃ x ∈ xs, x ≠ errorRank) :
|
||||
newMerge xs ≠ errorRank := by
|
||||
obtain ⟨x, hx, hne⟩ := h
|
||||
have hmem : x ∈ xs.filter (· ≠ errorRank) := List.mem_filter.mpr ⟨hx, by simpa using hne⟩
|
||||
unfold newMerge
|
||||
have hne' : ¬ (xs.filter (· ≠ errorRank)).isEmpty = true := by
|
||||
intro hempty
|
||||
rw [List.isEmpty_iff] at hempty
|
||||
rw [hempty] at hmem
|
||||
simp at hmem
|
||||
simp only [hne']
|
||||
apply mergeRank_not_error
|
||||
intro y hy
|
||||
simpa using (List.mem_filter.mp hy).2
|
||||
|
||||
/-- The retry is for infrastructure only: `scan` counts each failure by cause and the row is an
|
||||
infrastructure error only when there was a failure and every failure was infrastructure. -/
|
||||
def infraOnly (failures : List Bool) : Bool := decide (failures ≠ []) && failures.all id
|
||||
|
||||
theorem one_package_failure_is_not_infra : infraOnly [true, false] = false := by decide
|
||||
|
||||
theorem all_infra_failures_are_infra : infraOnly [true, true] = true := by decide
|
||||
|
||||
end Gohoarder.Security
|
||||
|
||||
Reference in New Issue
Block a user