fix(adapters): validate iat before it reaches the record, not after - #343
Open
harshnair75567-cloud wants to merge 1 commit into
Open
harshnair75567-cloud wants to merge 1 commit into
harshnair75567-cloud wants to merge 1 commit into
Conversation
SandboxSessionResult and AGTSessionResult wrote session.iat straight into build_trust_record's top-level "iat" key with no type check. Every other field reaches the record through a models.py pydantic constructor, which coerces or refuses a bad value before it is dumped -- iat bypassed all of them. TrustRecord.model_validate(), which sign_record's own docstring recommends for structural validity before writing, gave a false pass on a numeric-string iat: pydantic's lax mode coerces "1800000000" -> 1800000000 during validation, but that happens on a new object and never touches the dict being signed. The wire bytes kept the string, which jsonschema.validate against trace-v0.2.json and this library's own verify_record both then reject. AGTSessionResult additionally had no __post_init__ at all. Same failure mode as provenance.build_record's pre-agentrust-io#320 issued_at coercion, fixed there by validating the caller's explicit value before use instead of converting it. This applies the same fix to both adapters, mirroring _check_structure's bound (non-negative, <= JCS_SAFE_INTEGER, bool excluded since bool subclasses int). 1561 passed, 1 skipped. ruff and mypy clean on both changed source files. Signed-off-by: harshnair75567-cloud <harshnair75567@gmail.com>
harshnair75567-cloud
requested review from
a team and
lywinged
as code owners
September 14, 2026 13:48
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.
SandboxSessionResult and AGTSessionResult wrote session.iat straight into build_trust_record's top-level "iat" key with no type check. Every other field reaches the record through a models.py pydantic constructor, which coerces or refuses a bad value before it is dumped -- iat bypassed all of them.
TrustRecord.model_validate(), which sign_record's own docstring recommends for structural validity before writing, gave a false pass on a numeric-string iat: pydantic's lax mode coerces "1800000000" -> 1800000000 during validation, but that happens on a new object and never touches the dict being signed. The wire bytes kept the string, which jsonschema.validate against trace-v0.2.json and this library's own verify_record both then reject.
AGTSessionResult additionally had no post_init at all.
Same failure mode as provenance.build_record's pre-#320 issued_at coercion, fixed there by validating the caller's explicit value before use instead of converting it. This applies the same fix to both adapters, mirroring _check_structure's bound (non-negative, <= JCS_SAFE_INTEGER, bool excluded since bool subclasses int).
1561 passed, 1 skipped. ruff and mypy clean on both changed source files.
What this changes
Type of change
Spec section
Checklist
git commit -s)CHANGELOG.mdupdated (for any normative change)<!-- CHANGED: #NNN: description -->in spec text