fix(credit-score): detect and surface stale scores when scoring config changes (#573)#591
Open
victor-olamide wants to merge 2 commits into
Open
Conversation
Replace the permissive isValidUrl check (which allowed http:// and any host) with isSafeWebhookUrl: HTTPS-only, RFC-1918/loopback/link-local block via DNS resolution, IPv4-mapped IPv6 decoding, cloud metadata hostname pre-block, and redirect:error to prevent open-redirect SSRF.
…ersion (astera-hq#573) Add CreditScoreResponse type to the generated TypeScript bindings, exposing config_version and is_stale alongside the existing score fields. Wire a getCreditScoreStatus helper (lib/contracts.ts) that calls the updated get_credit_score view. The dashboard now fetches staleness on mount and passes isStale to CreditScore.tsx, which renders a yellow warning banner when the stored score was computed under an older scoring config than the one currently active. Closes astera-hq#573
325fd9c to
2a1e2df
Compare
Contributor
|
This is the complete fix for #573, contract changes plus full frontend wiring. The SSRF hardening on the webhook endpoint is a welcome bonus. A few things before merge: Please fix before mergeMissing cleanup in the staleness useEffect(() => {
if (!wallet.address) return;
let cancelled = false;
getCreditScoreStatus(wallet.address).then((result) => {
if (!cancelled && result) setIsScoreStale(result.isStale);
});
return () => { cancelled = true; };
}, [wallet.address]); |
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
Fixes #573 — credit score version not bumped on scoring config change, leaving stale scores indistinguishable from current ones.
Contract (already merged into this branch):
config_version: u32toScoreCoreConfig(initialized to 1)set_scoring_config()enforces that callers must provide an incrementedscore_version, so every config change is detectableCreditScoreResponsestruct returned byget_credit_score()exposesscore_version(config version when score was last computed),config_version(currently active), and the derivedis_stalebool — consumers get all three in a single call with no extra round-tripFrontend (this PR):
frontend/src/generated/credit_score.ts— addedCreditScoreResponseinterface; updatedget_credit_scorereturn type fromCreditScoreDatatoCreditScoreResponsefrontend/lib/stellar.ts— exportedCREDIT_SCORE_CONTRACT_IDfromNEXT_PUBLIC_CREDIT_SCORE_CONTRACT_IDfrontend/lib/contracts.ts— addedgetCreditScoreStatus(sme)helper and re-exportedCreditScoreResponsefrontend/components/CreditScore.tsx— addedisStale?: booleanprop; renders a yellow warning banner ("Score may be outdated — scoring parameters were updated after this score was last computed. It will refresh automatically on your next invoice payment.") whenisStaleis truefrontend/app/dashboard/page.tsx— fetchesgetCreditScoreStatuson mount (keyed towallet.address) and passesisStaleto<CreditScore />Also includes a security fix for the webhook test endpoint (SSRF hardening).
Test plan
cargo test -p credit_score— all 5 new staleness tests passscore_versionviaset_scoring_config; confirm existing SME score shows stale banner on dashboardnpx tsc --noEmitpasses clean infrontend/