Skip to content

Commit 5657a31

Browse files
committed
Require strict Context ABI hashes
1 parent a298bdb commit 5657a31

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

support/context_abi_scanner/lib/stack_lab/context_abi_scanner.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ defmodule StackLab.ContextABIScanner do
535535

536536
defp non_empty_strings?(_values), do: false
537537

538-
defp sha256?("sha256:" <> digest), do: String.length(digest) == 64
538+
defp sha256?("sha256:" <> digest), do: String.match?(digest, ~r/^[0-9a-f]{64}$/)
539539
defp sha256?(_value), do: false
540540

541541
defp status([]), do: :pass

support/context_abi_scanner/test/stack_lab/context_abi_scanner_test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ defmodule StackLab.ContextABIScannerTest do
5151
)
5252
end
5353

54+
test "rejects non-hex sha256 refs" do
55+
assert {:ok, receipt} =
56+
ContextABIScanner.scan(%{
57+
context_packets: [%{packet() | packet_hash: "sha256:" <> String.duplicate("z", 64)}],
58+
context_compile_receipts: [compile_receipt()],
59+
authority_grants: [grant()],
60+
admission_receipts: [admission_receipt()],
61+
route_decisions: [route_decision()],
62+
render_results: [render_result()],
63+
model_invocation_receipts: [model_receipt()],
64+
appkit_projections: [%{context_packet_ref: packet().context_packet_ref}],
65+
aitrace_facts: [%{trace_ref: packet().trace_ref}]
66+
})
67+
68+
assert receipt.status == :open_defect
69+
assert has_finding?(receipt, :context_packet_contract, {:invalid_sha256_ref, :packet_hash})
70+
end
71+
5472
test "rejects raw prompt and provider payload fields anywhere in the scan" do
5573
assert {:ok, receipt} =
5674
ContextABIScanner.scan(%{

0 commit comments

Comments
 (0)