fix: stroop precision, friendbot mainnet guard, server-only env guard… - #749
Merged
Jambox11 merged 1 commit intoAug 31, 2026
Merged
Conversation
…, API URL alias chain mux-labs#696 - validateSendAmount now rejects amounts with >7 decimal places (stroop precision). Added isStroopPrecise() + STROOP_DECIMALS to validateSendAmount.ts. xlmFormat.ts gains toStroopPrecision(), isExactStroopAmount(), XLM_MAX_DECIMALS, and MIN_XLM_AMOUNT. Tests updated with stroop edge cases. mux-labs#695 - friendbot.ts throws MainnetFriendbotError immediately when network is 'mainnet'. Added assertTestnetOnly() helper and MainnetFriendbotError class so callers can catch the specific error type. getFriendbotUrl() accepts an optional network param for backward compat. Tests updated. mux-labs#694 - env.ts gains assertServerSide() and getServerOnlyEnv(). Both throw at runtime when called from a browser context (window defined), surfacing any accidental client-side import of server-only vars (MUX_API_SECRET, MUX_API_KEY, etc.) visibly in development. Tests simulate a browser environment to verify. mux-labs#693 - config.ts: exported API_URL_CANDIDATES constant documents the exact three-alias priority order. getApiBaseUrl() now skips empty-string aliases so a mis-set deploy that blanks NEXT_PUBLIC_API_URL still picks up the legacy alias. Added getActiveApiUrlVar() for startup diagnostics. Deprecated getServerApiKey() as an alias of getApiKey(). Tests and docs updated.
|
@cyberpunk30 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Title:
fix: stroop precision, friendbot mainnet guard, server-only env guard, API URL alias chain
Description:
Closes #696
Closes #695
Closes #694
Closes #693
Summary
Four related hardening fixes across validation, security, and configuration.
#696 — Validate send amounts with stroop precision
Stellar amounts have at most 7 decimal places (1 stroop = 0.0000001 XLM).
Sending
1.00000001 XLMwould previously pass validation and be silentlytruncated by the network.
validateSendAmount()now rejects any amount with more than 7 decimal placesisStroopPrecise()helper andSTROOP_DECIMALS = 7constantxlmFormat.tsgainstoStroopPrecision(),isExactStroopAmount(),XLM_MAX_DECIMALS, andMIN_XLM_AMOUNT0.0000001✅,0.00000001❌#695 — Friendbot helper must refuse mainnet
Calling the Friendbot faucet against mainnet was a silent no-op at best and
exposes addresses to a public API at worst.
getFriendbotUrl()now throwsMainnetFriendbotErrorimmediately whennetwork === "mainnet"assertTestnetOnly()helper for explicit guards at call-sitesMainnetFriendbotErroris a named class so callers can catch it specificallynetworkparam is optional#694 — Do not bundle MUX_API_SECRET into client JS
Next.js strips non-
NEXT_PUBLIC_*vars at build time, but a future refactorcould accidentally import a server-only helper into a client component and get
a silent
undefinedrather than a visible error.assertServerSide(varName)toenv.ts— throws whenwindowis definedgetServerOnlyEnv(name)as the safe way to read server-only varsglobalThis.window = {}) to verify the guard#693 — Resolve NEXT_PUBLIC_API_URL vs NEXT_PUBLIC_MUX_API_URL vs NEXT_PUBLIC_API_BASE
Three aliases for the same concept with no documented priority and no protection
against blank-string mis-configuration.
API_URL_CANDIDATESconstant — single source of truth for the chaingetApiBaseUrl()now skips empty-string aliases (not justundefined), soNEXT_PUBLIC_API_URL=correctly falls through to the legacy aliasgetActiveApiUrlVar()for startup diagnostics/logginggetServerApiKey()deprecated in favour ofgetApiKey()Testing
All changes are covered by Vitest unit tests runnable via
pnpm test.No new dependencies. No production behavior changes — all guards are additive.