Skip to content

Fix: Replace z.httpUrl() with z.url() for localhost compatibility#249

Closed
taheerahmed wants to merge 2 commits into
e2b-dev:mainfrom
taheerahmed:fix/zod-localhost-validation
Closed

Fix: Replace z.httpUrl() with z.url() for localhost compatibility#249
taheerahmed wants to merge 2 commits into
e2b-dev:mainfrom
taheerahmed:fix/zod-localhost-validation

Conversation

@taheerahmed

Copy link
Copy Markdown
Contributor

Summary

  • Replaces z.httpUrl() with z.url() in the auth confirm route and shared ConfirmEmailInputSchema
  • z.httpUrl() rejects localhost URLs, causing Zod validation errors during local development email verification
  • z.url() validates URL structure while accepting localhost — production URLs (https://e2b.dev/...) continue to pass

Why this is safe

The Zod schema is only responsible for validating that next is a syntactically valid URL. The actual redirect security is handled downstream:

  • isExternalOrigin() checks reject or reroute requests with a different origin
  • buildRedirectUrl() reconstructs the redirect using the dashboard's own origin, only preserving pathname and search params

So switching from z.httpUrl() to z.url() does not weaken security.

Validation

URL z.httpUrl() (before) z.url() (after)
http://localhost:3000/dashboard FAIL PASS
https://e2b.dev/dashboard PASS PASS
not-a-url FAIL FAIL
(empty) FAIL FAIL

Files changed

  • src/server/api/models/auth.models.tsConfirmEmailInputSchema.next
  • src/app/api/auth/confirm/route.tsconfirmSchema.next

Closes #241

@vercel

vercel Bot commented Feb 25, 2026

Copy link
Copy Markdown

@taheerahmed is attempting to deploy a commit to the E2B Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e30060e057

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/app/api/auth/confirm/route.ts Outdated
…ocalhost compatibility

z.httpUrl() rejects localhost URLs, causing Zod validation errors
during local development when verifying email. z.url() with a protocol
constraint still restricts to http/https while accepting localhost.
Existing isExternalOrigin checks already handle redirect security.

Closes e2b-dev#241
@taheerahmed taheerahmed force-pushed the fix/zod-localhost-validation branch from e30060e to 14a91a3 Compare February 25, 2026 22:03
@ben-fornefeld

Copy link
Copy Markdown
Member

lgtm, can you add unit tests for this behavior and abstract the schema into lib/schemas/url.ts please?

@taheerahmed

Copy link
Copy Markdown
Contributor Author

will do this and update this was a miss from my end ! thanks for pointing it out !

… tests

- Extract shared httpUrlSchema into src/lib/schemas/url.ts alongside
  existing relativeUrlSchema
- Both auth confirm route and ConfirmEmailInputSchema now import from
  the shared schema instead of inlining z.url({ protocol: /^https?$/ })
- Add 12 unit tests covering http/https acceptance, localhost support,
  non-http scheme rejection, and invalid input handling
@taheerahmed

Copy link
Copy Markdown
Contributor Author

Done! Updated with:

  1. Abstracted schemahttpUrlSchema now lives in src/lib/schemas/url.ts alongside relativeUrlSchema. Both ConfirmEmailInputSchema and the confirm route's local schema import from there.

  2. Added 12 unit tests in src/__test__/unit/url-schema.test.ts covering:

    • Valid http/https URLs (production + localhost + 127.0.0.1)
    • Rejection of non-http schemes (mailto, ftp, file, javascript)
    • Rejection of invalid inputs (plain strings, empty strings)

All 92 unit tests pass (bun run test:unit).

ben-fornefeld pushed a commit that referenced this pull request May 20, 2026
## Summary

Fixes [#241](#241): Zod
validation error blocks email verification on local-dev Supabase setups.

- Replaces `z.httpUrl()` with a shared `httpUrlSchema` that uses
`z.url({ protocol: /^https?$/ })` — still requires http/https, but
accepts `http://localhost:3000/...`.
- Schema lives in `src/core/shared/schemas/url.ts` alongside the
existing `relativeUrlSchema`, and both the auth confirm route handler
and `ConfirmEmailInputSchema` consume it.
- Webhook URL validation
(`src/core/server/functions/webhooks/schema.ts`) intentionally kept on
`z.httpUrl()` — webhooks should not accept localhost.

## Files changed

- `src/core/shared/schemas/url.ts` — adds `httpUrlSchema` alongside
existing `relativeUrlSchema`
- `src/core/modules/auth/models.ts` — `ConfirmEmailInputSchema.next`
uses the shared schema
- `src/app/api/auth/confirm/route.ts` — same for the route's inline
`confirmSchema`
- `tests/unit/url-schema.test.ts` *(new)* — 12 unit tests covering
accept/reject cases

## Tests

```
bun run test:unit
bun run lint
```

## Credits
Adapted from #249 by @taheerahmed
@drankou

drankou commented May 21, 2026

Copy link
Copy Markdown
Contributor

Fixed in #327

@drankou drankou closed this May 21, 2026
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.

[Bug]: Zod validation error

3 participants