fix(web): harden csv-safe, seo, merchant-directory, and sold-count bounds (#848) #849
All Vouch review confidence checks passed
Residual risk 0.31 = Change Risk (0.50) × (1 − Review Confidence (0.39)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 636 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 31% · 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.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #849"
general
weight: 0.35
claude[bot]
Closes #848
Summary
---
<!-- dos-pr-summary -->
📌 TL;DR
This PR hardens multiple utility modules (
seo,csv-safe,merchant-directory,sold-count) against input validation vulnerabilities, including protocol-relative URL injection, CSV formula injection, control character smuggling, and DoS vectors via excessive data sizes or invalid locale tags.🎯 Type of Change
🔍 Changes Walkthrough
| File | Summary of Changes |
| :--- | :--- |
|
apps/web/src/lib/seo.ts|absoluteUrl: Added strict validation to reject protocol-relative URLs (//), credential-included URLs, non-HTTP(S) protocols, and cross-origin relative paths.fitTitle: Sanitized candidates by stripping control characters and normalizing whitespace; added bounds checking for themaxparameter to prevent NaN/Infinity issues. ||
apps/web/src/lib/csv-safe.ts|escapeCsvCell: Strips control characters (C0/C1) and truncates cells to 10,000 chars to prevent buffer bloat.buildSafeCsvContent: Enforces hard limits on columns (200) and rows (10,000) to mitigate DoS via massive CSV generation. ||
apps/web/src/lib/merchant-directory.ts|parseMerchantDirectoryFilters: Sanitizesqueryby stripping control chars and normalizing whitespace. Validatesplatformagainst a strict regex (/^[a-z0-9_-]{1,40}$/) to prevent XSS/injection.pageMerchantDirectory: Caps thelimitparameter at 500 to prevent excessive memory/CPU usage. ||
apps/web/src/lib/sold-count.ts|formatSoldCount: IntroducesMAX_DISPLAY_SOLD_COUNT(100M) to reject overflow values. AddsresolveSafeSoldLocaleto validate and canonicalize locale tags, falling back tovi-VNfor invalid inputs. Sanitizes display labels by stripping control characters. ||
apps/web/src/lib/__tests__/seo.test.ts| Added test cases verifying the new security guards forabsoluteUrl(phishing/credential injection),fitTitle(control chars/NaN), and CSV/merchant-directory bounds. ||
apps/web/src/lib/__tests__/sold-count.test.ts| Added test cases for overflow rejection, control character stripping in labels, and invalid locale fallback. |📊 Architectural Flow
<!-- /dos-pr-summary -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Improved page titles and links by cleaning invalid text and using a safe site URL when a link cannot be resolved.
Made CSV exports more reliable by cleaning cell content, limiting oversized data, and preserving negative numeric values.
Improved merchant directory searches and filters by cleaning query text, handling invalid platforms, and keeping page sizes within bounds.
* Improved sold-count displays by handling invalid or unusually large counts and formatting labels and numbers more consistently across locales.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->