Repository navigation
secret-alerts: HYP-01 verdict fields + Idris2 line contract (PROOF-POLICY §1) #1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9b80032
fix(secret-alerts): give each finding its HYP-01 verdict fields
claude 44e63ef
proof(abi): Idris2 contract for the secret-alerts line (PROOF-POLICY §1)
claude 8a8c6f2
Merge origin/main into the secret-alerts verdict branch (#1024)
claude 35311ce
test(secret-alerts): every finding is annotated and keeps its own fields
claude a71f4a9
Merge origin/main into the secret-alerts verdict branch (#1024)
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| -- SPDX-License-Identifier: MPL-2.0 | ||
| -- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> | ||
| -- | ||
| -- Hypatia ABI — the `hypatia secret-alerts` line contract | ||
| -- | ||
| -- `hypatia secret-alerts --owner O --repo R` prints one JSON line and exits. | ||
| -- A bash/jq consumer (the private estate secret-scanning sweep) reads the line | ||
| -- and the exit code, so the pair is a cross-language wire contract: PROOF-POLICY | ||
| -- §1 assigns it to Idris2. The Elixir producer is | ||
| -- `Hypatia.CLI.secret_alerts_output/3`; test/cli_test.exs ("secret-alerts") | ||
| -- exercises it. | ||
| -- | ||
| -- The contract: | ||
| -- * status "ok": the alerts were read. The line carries `total` and the | ||
| -- findings; `total` is the number of findings; exit code 0. | ||
| -- * status "error": the alerts could not be read (refused token, secret | ||
| -- scanning disabled, timeout, pagination cap). The line carries a | ||
| -- non-empty reason; exit code 3. | ||
| -- * A sweep classifies a line as Clean (ok, no findings), WithAlerts (ok, | ||
| -- at least one finding) or Unread (error). "Could not look" is never | ||
| -- "clean". | ||
| -- * Every finding is a pattern-supported HYP-01 verdict, so it is never | ||
| -- reported at level "sound". | ||
| -- | ||
| -- What is proved here (%default total, no proof-bypass primitives): | ||
| -- * the exit code is 0 exactly for status Ok, and 3 for Error | ||
| -- (`exitZeroIsOk`, `errorExitsThree`), and the status can be recovered | ||
| -- from the exit code (`statusOfExitRoundTrip`); | ||
| -- * no exit code other than 0 reads as Ok (`nonZeroNotOk`), so a crash | ||
| -- (exit 1) or a usage error (exit 2) is never taken for a clean read; | ||
| -- * an error line is always Unread, and a Clean line has exit 0 | ||
| -- (`errorIsUnread`, `cleanExitsZero`, `unreadIsError`); | ||
| -- * `total` equals the number of findings by construction (the findings | ||
| -- are a vector indexed by `total`; `totalIsLength`); | ||
| -- * every finding is pattern-supported and never "sound" | ||
| -- (`findingNeverSound`). | ||
| -- | ||
| -- What is NOT proved here: | ||
| -- * that the Elixir producer emits exactly this shape: the ExUnit tests | ||
| -- check it on sample data (TESTED), and this module does not prove | ||
| -- runtime refinement (PROOF-POLICY §2.1: a model does not prove the | ||
| -- implementation); | ||
| -- * anything about GitHub's API: pagination, rate limits and token scope | ||
| -- are the producer's job. | ||
|
|
||
| module Hypatia.ABI.SecretAlerts | ||
|
|
||
| import Data.List | ||
| import Data.Vect | ||
| import Hypatia.ABI.Verdict | ||
|
|
||
| %default total | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Section 1: Status and exit code | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| ||| Whether the alerts were read. | ||
| public export | ||
| data Status = Ok | Error | ||
|
|
||
| public export | ||
| Uninhabited (Ok = Error) where | ||
| uninhabited Refl impossible | ||
|
|
||
| public export | ||
| Uninhabited (Error = Ok) where | ||
| uninhabited Refl impossible | ||
|
|
||
| ||| The process exit code for each status. | ||
| public export | ||
| exitCode : Status -> Nat | ||
| exitCode Ok = 0 | ||
| exitCode Error = 3 | ||
|
|
||
| ||| Read a status back from an exit code. Any code but 0 and 3 (a crash, | ||
| ||| a usage error) is not a status line at all. | ||
| public export | ||
| statusOfExit : Nat -> Maybe Status | ||
| statusOfExit 0 = Just Ok | ||
| statusOfExit 3 = Just Error | ||
| statusOfExit _ = Nothing | ||
|
|
||
| ||| The exit code determines the status. | ||
| public export | ||
| statusOfExitRoundTrip : (s : Status) -> statusOfExit (exitCode s) = Just s | ||
| statusOfExitRoundTrip Ok = Refl | ||
| statusOfExitRoundTrip Error = Refl | ||
|
|
||
| ||| Exit 0 means Ok. | ||
| public export | ||
| exitZeroIsOk : (s : Status) -> exitCode s = 0 -> s = Ok | ||
| exitZeroIsOk Ok Refl = Refl | ||
| exitZeroIsOk Error prf = absurd prf | ||
|
|
||
| ||| An error exits 3, never 0. | ||
| public export | ||
| errorExitsThree : exitCode Error = 3 | ||
| errorExitsThree = Refl | ||
|
|
||
| ||| No non-zero exit code reads as Ok. | ||
| public export | ||
| nonZeroNotOk : (n : Nat) -> Not (n = 0) -> Not (statusOfExit n = Just Ok) | ||
| nonZeroNotOk 0 nz _ = nz Refl | ||
| nonZeroNotOk 1 _ prf = absurd prf | ||
| nonZeroNotOk 2 _ prf = absurd prf | ||
| nonZeroNotOk 3 _ prf = absurd (justInjective prf) | ||
| where | ||
| justInjective : Just Error = Just Ok -> Error = Ok | ||
| justInjective Refl impossible | ||
| nonZeroNotOk (S (S (S (S k)))) _ prf = absurd prf | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Section 2: The line | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| ||| A secret-scanning finding: a pattern-supported verdict (rule SSA001 to | ||
| ||| SSA004). The rule cannot assert a level; it is derived (HYP-01). | ||
| public export | ||
| record SecretFinding where | ||
| constructor MkSecretFinding | ||
| verdict : Verdict | ||
| isPattern : support verdict = Pattern | ||
|
|
||
| ||| A non-empty string, for an error reason. | ||
| public export | ||
| data NonEmptyString : String -> Type where | ||
| MkNonEmptyString : {0 s : String} -> NonEmpty (unpack s) -> NonEmptyString s | ||
|
|
||
| ||| One output line, indexed by its status. An Ok line's findings are a | ||
| ||| vector of length `count` (the wire `total`), so it cannot disagree with them. | ||
| public export | ||
| data AlertLine : Status -> Type where | ||
| OkLine : (owner, repo : String) -> (count : Nat) | ||
| -> (findings : Vect count SecretFinding) -> AlertLine Ok | ||
| ErrLine : (owner, repo : String) -> (reason : String) | ||
| -> NonEmptyString reason -> AlertLine Error | ||
|
|
||
| ||| The exit code a line is printed with. | ||
| public export | ||
| exitOf : {s : Status} -> AlertLine s -> Nat | ||
| exitOf {s} _ = exitCode s | ||
|
|
||
| ||| `total` is the number of findings. | ||
| public export | ||
| totalIsLength : (owner, repo : String) -> (n : Nat) -> (fs : Vect n SecretFinding) | ||
| -> length fs = n | ||
| totalIsLength _ _ n fs = lengthCorrect fs | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Section 3: How a sweep reads a line | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| ||| The three outcomes a sweep distinguishes. | ||
| public export | ||
| data Outcome = Clean | WithAlerts | Unread | ||
|
|
||
| public export | ||
| Uninhabited (Unread = Clean) where | ||
| uninhabited Refl impossible | ||
|
|
||
| ||| Classify a line. | ||
| public export | ||
| outcome : AlertLine s -> Outcome | ||
| outcome (OkLine _ _ 0 _) = Clean | ||
| outcome (OkLine _ _ (S _) _) = WithAlerts | ||
| outcome (ErrLine _ _ _ _) = Unread | ||
|
|
||
| ||| An error line is always Unread: "could not look" is never "clean". | ||
| public export | ||
| errorIsUnread : (l : AlertLine Error) -> outcome l = Unread | ||
| errorIsUnread (ErrLine _ _ _ _) = Refl | ||
|
|
||
| ||| An error line is never Clean. | ||
| public export | ||
| errorNeverClean : (l : AlertLine Error) -> Not (outcome l = Clean) | ||
| errorNeverClean l prf = absurd (trans (sym (errorIsUnread l)) prf) | ||
|
|
||
| ||| A Clean line was printed with exit code 0. | ||
| public export | ||
| cleanExitsZero : {s : Status} -> (l : AlertLine s) -> outcome l = Clean -> exitOf l = 0 | ||
| cleanExitsZero (OkLine _ _ 0 _) Refl = Refl | ||
| cleanExitsZero (OkLine _ _ (S _) _) prf = absurd prf | ||
| where | ||
| Uninhabited (WithAlerts = Clean) where | ||
| uninhabited Refl impossible | ||
| cleanExitsZero (ErrLine _ _ _ _) prf = absurd prf | ||
|
|
||
| ||| An Unread line has status Error. | ||
| public export | ||
| unreadIsError : {s : Status} -> (l : AlertLine s) -> outcome l = Unread -> s = Error | ||
| unreadIsError (OkLine _ _ 0 _) prf = absurd prf | ||
| where | ||
| Uninhabited (Clean = Unread) where | ||
| uninhabited Refl impossible | ||
| unreadIsError (OkLine _ _ (S _) _) prf = absurd prf | ||
| where | ||
| Uninhabited (WithAlerts = Unread) where | ||
| uninhabited Refl impossible | ||
| unreadIsError (ErrLine _ _ _ _) Refl = Refl | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| -- Section 4: Findings are never "sound" | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| ||| No secret-scanning finding is reported at level "sound". | ||
| public export | ||
| findingNeverSound : (f : SecretFinding) -> Not (level (verdict f) = LvSound) | ||
| findingNeverSound f = patternNeverSoundLevel (verdict f) (isPattern f) |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| -- SPDX-License-Identifier: MPL-2.0 | ||
| -- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> | ||
| -- | ||
| -- POSITIVE CONTROL (secret-alerts line contract). The counterparts of | ||
| -- tests/reject/SecretAlerts*.idr: a well-formed ok line with one | ||
| -- pattern-supported finding, and a well-formed error line, are accepted; | ||
| -- they classify as WithAlerts (exit 0) and Unread (exit 3); the finding is | ||
| -- never "sound". test/cli_test.exs ("secret-alerts") checks the Elixir | ||
| -- producer on the same shapes. | ||
|
|
||
| module SecretAlertsLines | ||
|
|
||
| import Data.List | ||
| import Data.Vect | ||
| import Hypatia.ABI.Verdict | ||
| import Hypatia.ABI.SecretAlerts | ||
|
|
||
| %default total | ||
|
|
||
| token : EvidenceToken | ||
| token = MkEvidenceToken "secret_scanning_alerts" "SSA001" "0.1.0" | ||
| (MkSpan "github_personal_access_token" 0 0) 1 | ||
|
|
||
| finding : SecretFinding | ||
| finding = MkSecretFinding (MkVerdict "open secret-scanning alert" [token] Pattern) Refl | ||
|
|
||
| okLine : AlertLine Ok | ||
| okLine = OkLine "acme" "demo" 1 [finding] | ||
|
|
||
| errLine : AlertLine Error | ||
| errLine = ErrLine "acme" "demo" "HTTP 404" | ||
| (MkNonEmptyString IsNonEmpty) | ||
|
|
||
| okHasAlerts : outcome SecretAlertsLines.okLine = WithAlerts | ||
| okHasAlerts = Refl | ||
|
|
||
| okExits0 : exitOf SecretAlertsLines.okLine = 0 | ||
| okExits0 = Refl | ||
|
|
||
| errUnread : outcome SecretAlertsLines.errLine = Unread | ||
| errUnread = Refl | ||
|
|
||
| errExits3 : exitOf SecretAlertsLines.errLine = 3 | ||
| errExits3 = Refl | ||
|
|
||
| findingIsEpi : level (verdict SecretAlertsLines.finding) = LvEpi | ||
| findingIsEpi = Refl | ||
|
|
||
| findingNotSound : Not (level (verdict SecretAlertsLines.finding) = LvSound) | ||
| findingNotSound = findingNeverSound SecretAlertsLines.finding |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- SPDX-License-Identifier: MPL-2.0 | ||
| -- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> | ||
| -- | ||
| -- EXPECTED REJECTION (secret-alerts line contract). scripts/check-verdicts.sh | ||
| -- passes only if Idris2 refuses this module, and only at `invalid`. | ||
| -- | ||
| -- Must fail: an error line names why the alerts could not be read. An | ||
| -- empty reason does not typecheck. | ||
| -- | ||
| -- EXPECT: Mismatch between: ?x :: ?xs and []. | ||
|
|
||
| module SecretAlertsEmptyReason | ||
|
|
||
| import Data.List | ||
| import Hypatia.ABI.SecretAlerts | ||
|
|
||
| %default total | ||
|
|
||
| invalid : AlertLine Error | ||
| invalid = ErrLine "acme" "demo" "" (MkNonEmptyString IsNonEmpty) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: hyperpolymath/hypatia
Length of output: 8524
Script executed:
Repository: hyperpolymath/hypatia
Length of output: 42045
Script executed:
Repository: hyperpolymath/hypatia
Length of output: 24846
Use the alert location for evidence spans.
For an open alert,
span.filecontains the secret type, not the file containing the secret. A consumer navigating the span can try to open the wrong file. Populate the span from the alert location instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed, and it stays as it is in this PR.
span.fileis the secret type because the rule setsfile: secret_type(lib/rules/secret_scanning_alerts.ex, lines 83 and 170 onmain), not because of this PR. The alert payload carries onlylocations_url, so a real file path needs one more API call per alert, to the locations endpoint. That changes the rule module's fetch path and is larger than this PR. The decision is with the owner.Generated by Claude Code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hyperpolymath Understood. The existing rule uses the secret type as
file, and fetching the alert location is outside this PR’s scope.Would you like me to open a GitHub issue for the follow-up?
You are interacting with an AI system.