Skip to content

validateApiUrl accepts any URL scheme, including javascript: and file:, as a valid NEXT_PUBLIC_API_URL #204

Closed

Description

@chonilius

src/lib/env.ts#validateApiUrl validates the API base URL purely by attempting to
construct a URL object:

export function validateApiUrl(raw: string | undefined): string {
  const value = raw === undefined || raw === "" ? DEFAULT_API_BASE_URL : raw;
  try {
    new URL(value);
  } catch {
    throw new EnvValidationError(...);
  }
  return value;
}

new URL(...) does not restrict the scheme — new URL("javascript:alert(1)"),
new URL("file:///etc/passwd"), and new URL("ftp://example.com") all construct
successfully and pass this check, even though none of them are meaningful as an HTTP API
base URL. A misconfigured deployment (e.g. a copy-paste error that includes a
javascript: or data: prefix, or a stray file:// from a local testing script left in
an environment file) would pass build-time validation and only fail much later, at the
actual fetch() call site in src/lib/api.ts, with a much less clear error than the one
this function was written to provide.

The function's own doc comment says it "checks the value is a well-formed URL (catches a
truncated paste, a missing protocol, stray whitespace, an empty string)" — accepting a
non-http(s) scheme is a well-formed URL that still isn't a valid API base URL, which is
what this function is meant to guard.

Suggested fix: after the new URL(value) parse succeeds, additionally assert
protocol === "http:" || protocol === "https:" and throw the same EnvValidationError
otherwise.

Activity

  1. added
    bug
    documentation
    very hard
    help wanted
    on Aug 21, 2026
  2. added
    Stellar Wave
    on Aug 24, 2026
  3. Hasmong commented on Aug 24, 2026

    @Hasmong

    @Hasmong has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hi there, this looks like something I'm well-equipped to handle, and I'm confident in my ability to resolve it correctly. Could you assign it to me?

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Hasmong to this issue.

  4. Joshua-echu commented on Aug 24, 2026

    @Joshua-echu

    @Joshua-echu has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I've reviewed the issue thoroughly and can start working on it right away. Looking forward to contributing

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Joshua-echu to this issue.

  5. larryjay007 commented on Aug 24, 2026

    @larryjay007

    @larryjay007 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hi, I can solve this issue as soon as possible and achieve the result you want. Please assign to me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @larryjay007 to this issue.

  6. khaylebfortune commented on Aug 24, 2026

    @khaylebfortune

    @khaylebfortune has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello Maintainer, I can fix this issue.
    Please assign me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @khaylebfortune to this issue.

  7. posimideveloper commented on Aug 24, 2026

    @posimideveloper
    Contributor

    @posimideveloper has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I'm ready to tackle this immediately.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @posimideveloper to this issue.

  8. faithylet commented on Aug 24, 2026

    @faithylet

    @faithylet has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hi maintainer,
    I have experience working with input validation, API security, and writing tests for edge cases. I can update validateApiUrl to properly restrict URL schemes, reject unsafe or unsupported schemes, and add comprehensive tests to prevent regressions.
    Assign it to me

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @faithylet to this issue.

  9. drips-wave commented on Aug 24, 2026

    @drips-wave

    Congratulations, @posimideveloper! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.

    🧑‍💻 @posimideveloper: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  10. added a commit that references this issue on Aug 25, 2026
    046aa16
  11. drips-wave commented on Aug 25, 2026

    @drips-wave

    This issue has been completed by @posimideveloper as part of the Stellar Wave Program's 8th Wave 🥳

    😎 @posimideveloper: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

  12. removed
    Stellar Wave
    on Oct 15, 2026
  13. added
    Stellar Wave
    on Oct 15, 2026
  14. removed
    Stellar Wave
    on Oct 15, 2026
  15. added
    Stellar Wave
    on Oct 15, 2026
  16. removed
    Stellar Wave
    on Oct 15, 2026
  17. added
    Stellar Wave
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Stellar Wavebugdocumentationhelp wantedvery hard

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions