fix(scoring): fail closed on a semantically-garbage 200 constants body - #1235
Merged
Conversation
#1192 pinned the upstream constants fetch and froze last-good on a non-2xx response, but a 200 with a semantically-garbage body — an HTML interstitial, a Git-LFS pointer, or a truncated file — parsed to ~0 recognized constants and silently reverted every constant to DEFAULT_SCORING_CONSTANTS while keeping sourceKind="raw-github", moving live scoring with no staleness signal. The refresh now applies a sanity floor: a 200 body must parse at least MIN_RECOGNIZED_SCORING_CONSTANTS recognized constants to be trusted. Otherwise it is handled exactly like a failed fetch — freeze the last-good snapshot, or bootstrap to a clearly-labeled "fallback" when there is no verified last-good. Also surfaces a warning when the upstream ref can't be resolved to an immutable SHA (the fetch falls back to the mutable ref), and records the resolved fetch ref in the drift-sync source.
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1235 +/- ##
=======================================
Coverage 94.92% 94.93%
=======================================
Files 173 173
Lines 19643 19650 +7
Branches 7062 7067 +5
=======================================
+ Hits 18647 18654 +7
Misses 397 397
Partials 599 599
🚀 New features to boost your workflow:
|
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes audit finding 3.6 (+ the drift-ref §4 item).
#1192pinned the upstream constants fetch and froze last-good on a non-2xx response — but a 200 with a semantically-garbage body (HTML interstitial, Git-LFS pointer, or truncated file) parsed to ~0 recognized constants and silently reverted every constant toDEFAULT_SCORING_CONSTANTSwhile keepingsourceKind="raw-github", moving live scoring with no staleness signal.Fix
MIN_RECOGNIZED_SCORING_CONSTANTS(8) recognized constants to be trusted. Below that it's handled exactly like a failed fetch — freeze the last-good snapshot, or bootstrap to a clearly-labeled"fallback"(never a deceptive"raw-github") when there's no verified last-good.fetchRefin the drift-sync source rather than the raw mutable ref.Scope
src/scoring/model.ts); no schema change; no migration; refresh is cron/internal-token gated (not contributor-reachable) — defense-in-depthValidation
npm run test:ci— full gate greennpm audit --audit-level=moderate— 0 vulnerabilitiesSafety
site//CNAME/lovable