← Back to Pull requests

Reject characters outside the base64 alphabet in contentEncoding #241

Open
unknown opened this pull request with 223 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 20, 2026 11:28 UTC
Author

contentEncoding: base64 accepts characters outside the base64 alphabet

The value is decoded with base64.b64decode(value), and with the default validate=False that drops every character outside A-Za-z0-9+/= before decoding, so only the leftover characters have to form valid base64:

>>> v = fastjsonschema.compile({'contentEncoding': 'base64'})
>>> v('aGVsbG8=" onerror="alert(1)')   # accepted
>>> v('aGVs bG8=')                     # accepted
>>> v('%%%%')                          # accepted, decodes to b''

RFC 4648 section 3.3 says decoders must reject data containing characters outside the alphabet, and the JSON-Schema-Test-Suite marks % as invalid (draft7 optional/content.json; that case only passes today because removing the % happens to leave a padding error). Content checks run on the data being validated, so a field declared as base64 can carry quotes, angle brackets, spaces or line breaks into code that expects the validated value to be plain base64, for example when it is put into a data: URL. The if data == "" check after the decode compares bytes with a str and never fires, so input that decodes to nothing is not caught either.

The decode now passes validate=True. Over about 8.7M generated strings per version on Python 3.10 to 3.14, the new check never accepts a string the old one rejected and never accepts a character outside the alphabet (on 3.12 and later it also rejects misplaced = padding). Whitespace and line breaks are rejected too, so MIME-style wrapped base64 no longer validates. The cases added to tests/test_string.py (draft 07 and 2019-09) fail on master and pass here, the full suite passes on Python 3.10 to 3.14, and pylint output is unchanged. CHANGELOG.txt has an entry under UNRELEASED.

Diff: 223 lines (+167 / -56) across 2 files Reviewer: bardrop Review duration: 2305m
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.37) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 223 lines diff across 2 files
0.37
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.324
Real PR Conversation Timeline
1 comments
"Review active on #241"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 36.8% (MEDIUM) · Higher = larger blast radius
36.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 19.6% · Safe to merge
19.6%