Fix two Datalog injection authorization bypasses; release 0.4.0 - #4
Merged
Conversation
Both SDKs built Biscuit Datalog by string interpolation, with no escaping or validation anywhere. ChainedToken.authorize() interpolated the requested tool name into the authorizer source. A tool name that closed its own string could append an in-allowlist tool() fact and `allow if true`, so a token granting only tool:search authorized any tool. No malicious token, no forged signature and no control of the issuer was needed, only influence over the tool name being checked. In an MCP binding that name arrives directly from the agent's JSON-RPC params.name. create_authority() and delegate() interpolated the issuer, principal, scope, delegator, delegate and context values into block Datalog, so a breakout in any of them injected facts into a block that was then signed. An injected tool() fact satisfied the authority block's own scope check for any tool, an injected time() fact defeated expiry, and an injected max_depth() ahead of the real one was what the V3 check read. validate_term() now rejects the double quote, the backslash and control characters at every boundary where a caller-supplied string becomes Datalog. Those are the only characters that can escape a string context; semicolons, parentheses, brackets, commas, //, spaces, colons and non-ASCII all round-trip unambiguously and keep working. The authorize() path additionally binds the tool as a Datalog parameter instead of interpolating it. Also fixes SimplePolicy.to_datalog(), which emitted a check over budget and depth in both languages. Section 3.4.1 requires budget_ceiling(N) and max_depth(N) as facts and forbids a budget check outright, because such a check binds to ambient facts rather than the block's own ceiling. The chained builders were already correct; SimplePolicy had drifted because the canonical encoding was implemented twice per SDK. It now lives in one module per language, with cross-language vectors comparing the two renderings byte for byte and regression tests for both bypasses.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
Two authorization bypasses, both caused by building Biscuit Datalog with string interpolation. Present identically in the Python and Rust SDKs, with forged tokens portable between them.
F1 — authorizer injection in
ChainedToken.authorize(). The requested tool name was interpolated into the authorizer source. A tool name that closed its own string could append an in-allowlisttool()fact andallow if true, so a token granting onlytool:searchauthorized any tool.This required no malicious token, no forged signature and no control of the issuer, only influence over the tool name being checked. In an MCP binding that name arrives directly from the agent's JSON-RPC
params.name.F2 — block-encoder injection in
create_authority()anddelegate(). The issuer, principal, scope, delegator, delegate and context values were interpolated into block Datalog, so a breakout in any of them injected facts into a block that was then signed:That token is cryptographically valid, every signature chains, and it authorizes everything.
Fix
validate_term()rejects the double quote, the backslash and control characters at every boundary where a caller-supplied string becomes Datalog. Those are the only characters that can escape a Datalog string context. Semicolons, parentheses, brackets, commas,//, spaces, colons and non-ASCII characters round-trip unambiguously and keep working, so ordinary identifiers and free-form context are unaffected.authorize()additionally binds the tool as a Datalog parameter rather than interpolating it.Also in this release
SimplePolicy.to_datalog()emittedcheck if budget($b), $b <= Nandcheck if depth($d), $d <= Nin both SDKs. Section 3.4.1 of draft-prakash-aip-01 requires these as the factsbudget_ceiling(N)andmax_depth(N), and forbids a budget check outright: it binds to whatever budget facts are in scope at evaluation rather than to the block's own ceiling, so it either rejects valid chains or passes unconditionally.The chained builders were already correct.
SimplePolicyhad drifted because the canonical encoding was implemented twice per SDK. It now lives in one module per language (aip_token.canonical,aip_token::canonical).Note: both SDKs agreed with each other and both violated the spec, so cross-language interop tests passed the whole time. The test that catches this asserts the spec's MUST NOT directly.
Verification
New: regression tests for both bypasses in each language, and conformance vectors comparing the Rust and Python renderings byte for byte.
The one pre-existing Python failure (
test_adk_adapter.py::test_register_walks_sub_agents) is unrelated and reproduces onmasterwithout these changes.Breaking
SimplePolicy.to_datalog()output has changed to the canonical Section 3.4.1 form.token_malformed.