Skip to content

fix(scorechain): drop code default for risk threshold — fail loud instead of defaulting#4103

Merged
TaprootFreak merged 1 commit into
developfrom
fix/scorechain-risk-threshold-no-fallback
Jul 6, 2026
Merged

fix(scorechain): drop code default for risk threshold — fail loud instead of defaulting#4103
TaprootFreak merged 1 commit into
developfrom
fix/scorechain-risk-threshold-no-fallback

Conversation

@TaprootFreak

@TaprootFreak TaprootFreak commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Removes the code fallback for the Scorechain risk threshold. The value now comes solely from the SCORECHAIN_RISK_THRESHOLD env var — no code default — so a missing value fails loud instead of silently defaulting.

Changes

  • config (config.ts): SCORECHAIN_RISK_THRESHOLD unset → undefined (was ?? 70). riskThreshold: number | undefined.
  • isHighRisk (scorechain-screening.service.ts): throws if the threshold is null/NaN. A missing value must not silently disable the gate (riskScore < undefined/NaN is always false). The throw is caught by the screenScorechain callers (buy-crypto / buy-fiat preparation) and routes the tx to manual review — fail-closed + loud.
  • test (scorechain-screening.service.spec.ts): sets SCORECHAIN_RISK_THRESHOLD=70 in beforeAll (restored in afterAll) so the score-vs-threshold assertions stay deterministic. Only this spec calls the real isHighRisk; the buy-crypto/buy-fiat preparation specs mock it.
  • docs: drop the now-stale "(default 70)" from the spec.

Scope / safety

  • The value is provided as an env var by the deployment environment; prod + dev already set it, so no throw in real environments.
  • No entity/schema change. riskThreshold is read only by isHighRisk, so no other consumer sees the widened type.
  • Locally isHighRisk is unreachable without SCORECHAIN_API_KEY (the screenScorechain gate returns early), so a local run without the threshold does not throw.

@TaprootFreak

TaprootFreak commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

Completed in 2 review passes, each running an independent conformity review and a logic/security review in parallel — 0 issues on both passes:

  • Logic/correctness (compliance-critical): verified end-to-end that removing the ?? 70 default cannot silently disable the gate — isHighRisk throws on null/NaN, and the throw is caught by both screenScorechain callers (buy-crypto / buy-fiat preparation) → SCORECHAIN_HIGH_RISK → PENDING manual review (fail-closed + loud). riskThreshold is read by no other consumer, so the number | undefined widening breaks nothing.
  • Tests: the screening spec sets the threshold explicitly (70, restored in afterAll) so the score-vs-threshold assertions stay deterministic; only this spec calls the real isHighRisk (the prep specs mock it).

The value is provided as an env var by the deployment environment; prod + dev already set it, so no throw in real environments. All CI checks green.

(Branch history was rewritten to keep infrastructure/deployment details out of this public repo; content is otherwise unchanged.)

@TaprootFreak TaprootFreak marked this pull request as ready for review July 6, 2026 12:46
@TaprootFreak TaprootFreak requested a review from davidleomay as a code owner July 6, 2026 12:46
@TaprootFreak TaprootFreak force-pushed the fix/scorechain-risk-threshold-no-fallback branch from e999198 to 179ebef Compare July 6, 2026 13:36
…tead of defaulting

The Scorechain risk threshold has no code fallback anymore; the value comes solely from the SCORECHAIN_RISK_THRESHOLD env var.

- config: unset => undefined (was `?? 70`).
- isHighRisk: throw if the threshold is null/NaN. A missing value must not silently disable the gate (`riskScore < undefined/NaN` is always false); the throw is caught by the screenScorechain callers and routes the tx to manual review (fail-closed + loud).
- test: the screening spec sets the threshold explicitly (70) so the score-vs-threshold assertions stay deterministic without an ambient default.
- docs: drop the now-stale "(default 70)" from the spec.
@TaprootFreak TaprootFreak force-pushed the fix/scorechain-risk-threshold-no-fallback branch from 179ebef to 2bdcb98 Compare July 6, 2026 13:52
@TaprootFreak TaprootFreak merged commit eb288f6 into develop Jul 6, 2026
7 checks passed
@TaprootFreak TaprootFreak deleted the fix/scorechain-risk-threshold-no-fallback branch July 6, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant