fix(extension): harden security-guards and detector JSON-LD/ID bounds (#846) #847
All Vouch review confidence checks passed
Residual risk 0.43 = Change Risk (0.71) × (1 − Review Confidence (0.39)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.71 · 534 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 41% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
Diff Size
diff_size
0.376
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.071
Real PR Conversation Timeline
1 comments
"Review active on #847"
general
weight: 0.35
claude[bot]
Closes #846
Summary
- Hardens sanitizeExtensionProductSignal to strip control characters (/\p{Cc}+/gu) and collapse whitespace on itle (<= 500 chars) and selectedVariant (<= 200 chars), validate/canonicalize canonicalUrl (<= 2048 chars, http:/https:, no embedded userinfo credentials), and validate externalItemId/externalShopId (<= 120 chars, /^[a-zA-Z0-9_.-]{1,120}$/).
- Hardens escapeSafeExternalHref to strip control characters, enforce <= 2048 chars, and reject URLs containing embedded userinfo credentials.
- Bounds ilterValidSparklinePrices to at most 365 valid points.
- Hardens sanitizeProductUrl and detectEcommercePlatform to strip control characters, enforce <= 2048 chars, and reject embedded userinfo credentials.
- Bounds extractIdsFromUrl numeric IDs (1..24 digits), TikTok shop handles (1..64 chars), and retail slugs (2..120 safe slug chars).
- Caps lattenJsonLdEntities and extractPriceFromJsonLdOffers at 100 entities/offers to prevent main-thread stalls on oversized JSON-LD graphs.
- Adds regression suite #846.
---
<!-- dos-pr-summary -->
📌 TL;DR
This PR hardens the browser extension's e-commerce data extraction pipeline against Denial of Service (DoS) and injection attacks by enforcing strict input sanitization, length limits, and entity caps on URLs, JSON-LD structures, and external identifiers.
🎯 Type of Change
🔍 Changes Walkthrough
| File | Summary of Changes |
| :--- | :--- |
|
apps/extension/src/extractors/ecommerce-detector.ts| Added input validation tosanitizeProductUrlanddetectEcommercePlatformto reject URLs with credentials, excessive length, or control characters. Enforced length limits on extracted IDs (Shop/Item) and added caps (MAX_JSON_LD_ENTITIES,MAX_JSON_LD_OFFERS) to prevent memory exhaustion from maliciously large JSON-LD graphs. ||
apps/extension/src/security-guards.ts| IntroducedsanitizeExternalIdentifierandsanitizeCanonicalSignalUrlto strictly validate and clean external IDs and URLs. EnhancedsanitizeExtensionProductSignalto strip control characters from titles/variants and apply the new URL/ID sanitizers. UpdatedescapeSafeExternalHrefto reject credential-laden or oversized URLs. AddedMAX_SPARKLINE_POINTSto limit the size of price history arrays. ||
apps/extension/src/test-extension-pipeline.ts| Added comprehensive test cases verifying the new security guards: rejection of credential URLs, handling of oversized inputs, stripping of control characters, and enforcement of JSON-LD/sparkline entity limits. |📊 Architectural Flow
<!-- /dos-pr-summary -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
- Improved handling of product information from online stores by filtering malformed or excessively long links and product identifiers.
- Product titles and selected variants are cleaned up, and links containing unsafe credentials or characters are rejected.
- Price history is limited to the latest 365 valid entries, and extracted product data is bounded to help prevent oversized results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->