fix(annotator,types): bound untrusted strings flowing into the YAML sidecar (#232)#243
Merged
Merged
Conversation
…idecar (#232) caseName, citation, statuteVersionRef and statuteVersionNote were unbounded z.string()s. They originate from CourtListener and are written into a hand-rolled YAML sidecar, so an arbitrarily long value could bloat output and widen the injection surface. - Add length caps to CaseAnnotationSchema: caseName(500), citation(200), statuteVersionRef(100), statuteVersionNote(500) — a fail-closed backstop so nothing over-cap is ever serialized. - Generalize the snippet truncation into truncate(value, max): it slices by UTF-16 code unit (matching the schema's code-unit caps) and drops a trailing lone high surrogate so a split never leaves a broken character. Apply it to caseName and citation (in addition to holdingSummary) so legitimately long values are clamped rather than dropped by validation. Adds schema cap tests and annotator truncation/surrogate-guard tests. Closes #232 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
Summary
caseName,citation,statuteVersionRef, andstatuteVersionNotewere unboundedz.string()s. They originate from the CourtListener API and are written into a hand-rolled YAML sidecar, so an arbitrarily long (hostile or accidental) value could bloat output and widen the injection surface.Fix
CaseAnnotationSchemanow boundscaseName≤ 500,citation≤ 200,statuteVersionRef≤ 100,statuteVersionNote≤ 500 (holdingSummarywas already 500). Nothing over-cap can ever be serialized.truncate(value, max)— slices by UTF-16 code unit (matching the schema's code-unit caps) and drops a trailing lone high surrogate so a split never leaves a broken character. Applied tocaseNameandcitation(alongsideholdingSummary), so legitimately long values are clamped rather than dropped by validation.Tests
schemas.test.ts: each cap rejects over-length and accepts at-cap.annotator.test.ts: over-cap untrusted fields are clamped so the annotation still validates; truncation that splits an emoji surrogate pair never leaves a lone high surrogate before the ellipsis.Full local CI (build + typecheck + lint + test) green.
Closes #232