fix(cli): hash the approval token the relay stored, not the spelling - #6878
Open
Chessing234 wants to merge 1 commit into
Open
fix(cli): hash the approval token the relay stored, not the spelling#6878Chessing234 wants to merge 1 commit into
Chessing234 wants to merge 1 commit into
Conversation
workflows approve computes hex(SHA256(approval_token.as_bytes())) over the argument exactly as typed. The token the relay stored came from generate_approval_token, i.e. Uuid::new_v4().to_string() — canonical lowercase hyphenated — and the relay looks the approval up by the digest of that string. validate_uuid passes four spellings of the same UUID, and three of them hash to a digest the relay has never seen. get_approval_by_stored_hash then finds nothing and the ingest is refused as "approval not found", which points whoever ran it at an expired or already-answered request rather than at their own paste. Parse first and hash the canonical form, in one helper so the relay's half of the contract has somewhere to be pinned. The same canonicalization is applied to the four workflow queries, which filter #h/#d on the raw argument and so return an empty list — or, in workflows update, "workflow not found" — for a workflow that exists. workflows update already had the parsed value on the line above. Signed-off-by: Taksh <takshkothari09@gmail.com>
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.
Found by reading
cmd_approve_stepagainst the relay's lookup; no issue filed.The approval token is hashed as typed
The comment is right about the contract and the code hashes the wrong bytes. The token the relay stored came from
generate_approval_token(crates/buzz-workflow/src/executor.rs:779):— canonical lowercase hyphenated — and
handle_workflow_approvallooks it up by the digest of that string (command_executor.rs:1036-1044,get_approval_by_stored_hash).validate_uuidonly checks that the argument parses, andUuid::parse_straccepts uppercase, the unhyphenated 32-character form, braces, and aurn:uuid:prefix. Three of those four spellings hash to a digest the relay has never stored, so the lookup misses and the ingest is refused as:which is the same message a genuinely expired or already-answered approval produces. The operator holds a valid, pending token and is told it doesn't exist — so they go looking at the workflow run, not at their paste. Uppercase is not a contrived input here: it's what you get from a token copied out of a system that upper-cases identifiers, or typed from a screenshot.
The fix parses first and hashes the canonical form, in a small helper so the relay's half of the contract has somewhere to be pinned by a test.
Four workflow queries have the same gap
workflows list,workflows get,workflows runsandworkflows updatecallvalidate_uuidand then put the raw argument into#h/#d. Everyh/dtag in the tree is canonical and a NIP-01 generic tag filter compares byte for byte, so a non-canonical spelling matches nothing:workflows updateis the worst of the four — its revision lookup misses, so it exits withworkflow <id> not foundfor a workflow that exists. It already hadlet wf_uuid = parse_uuid(workflow_id)?on the line above and was still filtering on the string.Tests
Three in
approval_token_tests: every spellingvalidate_uuidaccepts hashes to the same digest as the canonical one; the digest is pinned ashex(SHA256(canonical bytes))so a change to either side of the contract is a red test rather than another "approval not found"; and a non-UUID token is a usage error.Related
Same root cause as #6877 (
channels/messages), and as #5966 / #5970 / #5984 for the hex-id half. Independent diffs — no shared symbols, no overlapping files.reposandprojectsstill have the query half of this; separate PR.Testing
cargo test -p buzz-cli --lib— 366 passed, 0 failedcargo clippy -p buzz-cli --all-targets— cleancargo fmt --all -- --check— cleanNot exercised against a live relay: the "approval not found" claim is read from
get_approval_by_stored_hashand theIngestError::Rejectedarm above it, not observed.