Skip to content

fix(importer): harden review jobs against NaN cap and proto keys - #1857

Merged
JOY (JOY) merged 2 commits into
devfrom
fix/1853-review-jobs-hardening
Nov 22, 2026
Merged

JOY (JOY) merged 2 commits into
devfrom
fix/1853-review-jobs-hardening

Conversation

@JOY

@JOY JOY (JOY) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Spend-cap fail-closed hardening (apps/importer/src/shopee/jobs/review-ai-points.ts): Parse cost_usd and reserved_usd strictly in monthSpendUsd so non-finite or empty strings ("NaN", NaN, Infinity, "Infinity", "-Infinity", ""), missing/negative open-batch reserved_usd, invalid row objects, or malformed submitted_at timestamps return +Infinity instead of NaN; fall back to non-negative reserved_usd when cost_usd < 0; parse month-boundary timestamps with Date.parse; and guard result.capped when monthSpendUsd or reservedUsd is non-finite.
  • Prototype-key guards (apps/importer/src/shopee/jobs/review-ai-points.ts, apps/importer/src/shopee/product-points-ai-prompt.ts): Replace if (key in total) with Object.hasOwn(total, key) (plus finite positive count check) in storeAiRows, and allocate byCriterion via Object.create(null) in mergeAndSelectAiProductPoints so __proto__, constructor, and toString never read or mutate Object.prototype.
  • Finite cost and rating bounds (apps/importer/src/shopee/review-ai-prompt.ts, apps/importer/src/shopee/jobs/review-ai-points.ts, apps/importer/src/shopee/jobs/review-values.ts): Guard batchCostUsd with isReviewAiModel(model), Number.isFinite(v) && v > 0, and pre-multiplication / 1_000_000 division; clamp accumulated request token usage in collectBatch to Number.MAX_SAFE_INTEGER; and guard expectedMasterRatings against non-finite criteria_ratings, rating_star / rating_exact, non-finite or huge helpfulness_weight (Math.min(weight, 3)), and prototype criterion keys before toUnits(..., BigInt).
  • UTF-16 surrogate and path-segment safety (apps/importer/src/shopee/jobs/review-ai-points.ts, apps/importer/src/shopee/logger.ts): Normalize external batch/file IDs with .toWellFormed().trim() and reject empty, dot-segment (".", ".."), slash, query/hash, or control-char resource IDs before encodeURIComponent; truncate at UTF-16 code-point boundaries plus .toWellFormed() in sanitizeAiGeneratedText so slicing at boundedInput or safeMaxLen never leaves a lone surrogate or exceeds maxLen.

Verification

Closes #1853
Claimant: antigravity:93ebb889-4915-4c9f-bb0b-53a96791ec91

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rate Ready Ready Preview Nov 22, 2026 10:17am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 753a6870-b696-4c76-903a-fd3d868f53d7
Commits

Reviewing files that changed from the base of the PR and between 64bbf72 and 107f6fc.

Files selected for processing: 7

  • apps/importer/src/shopee/__tests__/review-ai-points.test.ts
  • apps/importer/src/shopee/__tests__/review-values.test.ts
  • apps/importer/src/shopee/jobs/review-ai-points.ts
  • apps/importer/src/shopee/jobs/review-values.ts
  • apps/importer/src/shopee/logger.ts
  • apps/importer/src/shopee/product-points-ai-prompt.ts
  • apps/importer/src/shopee/review-ai-prompt.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Code Review completed (7 eligible files · 25,812 chars · 1 model call(s) · 1 PR unit(s))

Whole diff with bounded context at base 64bbf72 / head 9682b30.

✅ CLEAN_PASS: Complete diff reviewed

dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Code Review completed (7 eligible files · 30,769 chars · 2 model call(s) · 2 PR unit(s))

Whole diff with bounded context at base 64bbf72 / head 107f6fc.

✅ No verified defects

1 possible issue(s) could not be grounded in or verified against the snapshot source, so they are not published.

@JOY

Copy link
Copy Markdown
Contributor Author

PO acceptance: merge at 107f6fc

@JOY
JOY (JOY) merged commit 4aefe8b into dev Nov 22, 2026
18 checks passed
@JOY
JOY (JOY) deleted the fix/1853-review-jobs-hardening branch November 22, 2026 10:28
@JOY JOY (JOY) mentioned this pull request Nov 22, 2026
2 of 6 tasks

This branch was successfully deployed

1 active deployment
Preview — 107f6fc7 Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(importer): harden review jobs against NaN spend-cap bypass and prototype keys

1 participant