← Back to Pull requests

fix(extension): harden security-guards and detector JSON-LD/ID bounds (#846) #847

Closed
unknown closed this pull request without merging on Oct 24, 2026 12:25 UTC
View on GitHub
unknown unknown commented on Oct 24, 2026 12:19 UTC
Author

Closes #846

Summary


  • pps/extension/src/security-guards.ts:

  • - 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.
  • pps/extension/src/extractors/ecommerce-detector.ts:

  • - 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.
  • pps/extension/src/test-extension-pipeline.ts:

  • - 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


  • 🚀 New feature

  • 🐛 Bugfix

  • 🧹 Refactor

  • ⚡ Performance

  • 📚 Documentation

  • ⚙️ CI / Configuration
  • 🔍 Changes Walkthrough


    | File | Summary of Changes |
    | :--- | :--- |
    | apps/extension/src/extractors/ecommerce-detector.ts | Added input validation to sanitizeProductUrl and detectEcommercePlatform to 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 | Introduced sanitizeExternalIdentifier and sanitizeCanonicalSignalUrl to strictly validate and clean external IDs and URLs. Enhanced sanitizeExtensionProductSignal to strip control characters from titles/variants and apply the new URL/ID sanitizers. Updated escapeSafeExternalHref to reject credential-laden or oversized URLs. Added MAX_SPARKLINE_POINTS to 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


    flowchart TD
        A[Raw Input: URL / JSON-LD / ID] --> B{Input Validation}
        
        B -->|Invalid Type / Control Chars / Too Long| C[Reject / Return Null]
        B -->|Contains Credentials| C
        B -->|Valid| D[Sanitize & Parse]
        
        D --> E{Data Type}
        E -->|URL| F[Strip Query/Hash<br>Return Origin+Path]
        E -->|External ID| G[Regex Validate<br>Length Check]
        E -->|JSON-LD Graph| H[Flatten Entities]
        E -->|Price History| I[Filter Valid Prices]
        
        H --> J{Entity Count > 100?}
        J -->|Yes| K[Truncate to 100]
        J -->|No| L[Keep All]
        
        I --> M{Point Count > 365?}
        M -->|Yes| N[Keep Last 365]
        M -->|No| O[Keep All]
        
        F --> P[Safe Output]
        G --> P
        K --> P
        L --> P
        N --> P
        O --> P
    

    <!-- /dos-pr-summary -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

  • Bug Fixes

  • - 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 -->

    Diff: 534 lines (+400 / -134) across 6 files Reviewer: claude[bot] Review duration: 5m
    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
    0.71
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 41% · Reviewer familiarity: 35%
    38%
    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
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 39.0% reviewed sensitive_module
    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: 71.1% (HIGH) · Higher = larger blast radius
    71.1%
    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: 39.0% · Lower = rushed or shallow review
    39.0%
    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: 43.4% · Moderate risk
    43.4%
    Repository