[GH-ISSUE #3812] When signing up with email verification, callbackURL decodes encoded uri component #18363

Closed
opened 2026-04-15 16:48:55 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @dccarmo on GitHub (Aug 5, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3812

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Create a callbackURL with a query parameter that contains an enconded parameter:

http://127.0.0.1:4321/sign-in?verifiedEmail=email%2B11%40gmail.com

When receiving the email with the token, it correctly shows the encoded callbackURL:

http://127.0.0.1:4321/api/auth/verify-email?token=(...)&callbackURL=http://127.0.0.1:4321/sign-in?verifiedEmail=email%2B11%40gmail.com

But when clicking on the link and being redirected to the URL, it's already decoded:

http://127.0.0.1:4321/sign-in?verifiedEmail=email+11@gmail.com

Which then breaks url.searchParams because it decodes + as empty space.

Current vs. Expected behavior

I expected the callback URL to be redirected exactly as it's created.

What version of Better Auth are you using?

1.3.2

Provide environment information

- OS: macOS 15.5
- Browser: Firefox 140.0.4

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

export const auth = betterAuth({
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: true,
  },
});

Additional context

Originally created by @dccarmo on GitHub (Aug 5, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3812 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Create a `callbackURL` with a query parameter that contains an enconded parameter: ``` http://127.0.0.1:4321/sign-in?verifiedEmail=email%2B11%40gmail.com ``` When receiving the email with the token, it correctly shows the encoded `callbackURL`: ``` http://127.0.0.1:4321/api/auth/verify-email?token=(...)&callbackURL=http://127.0.0.1:4321/sign-in?verifiedEmail=email%2B11%40gmail.com ``` But when clicking on the link and being redirected to the URL, it's already decoded: ``` http://127.0.0.1:4321/sign-in?verifiedEmail=email+11@gmail.com ``` Which then breaks `url.searchParams` because it decodes `+` as empty space. ### Current vs. Expected behavior I expected the callback URL to be redirected exactly as it's created. ### What version of Better Auth are you using? 1.3.2 ### Provide environment information ```bash - OS: macOS 15.5 - Browser: Firefox 140.0.4 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ emailAndPassword: { enabled: true, requireEmailVerification: true, }, }); ``` ### Additional context - I'm running better-auth inside Astro. - Possibly related to: https://github.com/better-auth/better-auth/issues/2592
GiteaMirror added the locked label 2026-04-15 16:48:55 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 5, 2025):

Hi @dccarmo! I'm Dosu and I’m helping the better-auth team.

This is a known bug in Better Auth v1.3.2: the backend decodes the callbackURL parameter before redirecting, which causes encoded characters like + (from %2B) to become spaces. This breaks url.searchParams parsing because + is not preserved as intended. The issue is confirmed in the code and discussed in related issues and PRs (example, issue #2592). There’s no config option to change this behavior in v1.3.2.

Workarounds are limited: you could try double-encoding the callbackURL (encode it twice before passing it in, then decode it twice on the frontend), or handle the parameter parsing manually on the frontend to account for spaces. The most robust fix is to upgrade to a newer version of Better Auth, as maintainers have addressed callbackURL encoding/decoding bugs in later releases.

This problem is not specific to Astro or your browser—it's due to how Better Auth handles callbackURL decoding during the verification flow.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3156151465 --> @dosubot[bot] commented on GitHub (Aug 5, 2025): <!-- Greeting --> Hi @dccarmo! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known bug in Better Auth v1.3.2: the backend decodes the callbackURL parameter before redirecting, which causes encoded characters like `+` (from `%2B`) to become spaces. This breaks `url.searchParams` parsing because `+` is not preserved as intended. The issue is confirmed in the code and discussed in related issues and PRs ([example](https://github.com/better-auth/better-auth/pull/3268), [issue #2592](https://github.com/better-auth/better-auth/issues/2592)). There’s no config option to change this behavior in v1.3.2. Workarounds are limited: you could try double-encoding the callbackURL (encode it twice before passing it in, then decode it twice on the frontend), or handle the parameter parsing manually on the frontend to account for spaces. The most robust fix is to upgrade to a newer version of Better Auth, as maintainers have addressed callbackURL encoding/decoding bugs in later releases. This problem is not specific to Astro or your browser—it's due to how Better Auth handles callbackURL decoding during the verification flow. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/e2ffb424-cbdc-4123-ac38-b773da81cb4a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/e2ffb424-cbdc-4123-ac38-b773da81cb4a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/e2ffb424-cbdc-4123-ac38-b773da81cb4a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/e2ffb424-cbdc-4123-ac38-b773da81cb4a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e2ffb424-cbdc-4123-ac38-b773da81cb4a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/e2ffb424-cbdc-4123-ac38-b773da81cb4a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e2ffb424-cbdc-4123-ac38-b773da81cb4a?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3812)
Author
Owner

@Kinfe123 commented on GitHub (Aug 7, 2025):

Could you check on test #3863 or update it to the latest version? Also, if there’s any additional context, could you please share a bit more detail?

<!-- gh-comment-id:3165554768 --> @Kinfe123 commented on GitHub (Aug 7, 2025): Could you check on test #3863 or update it to the latest version? Also, if there’s any additional context, could you please share a bit more detail?
Author
Owner

@dosubot[bot] commented on GitHub (Nov 6, 2025):

Hi, @dccarmo. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that in Better Auth v1.3.2, the callbackURL query parameter with an encoded email is decoded incorrectly on redirect, causing issues like + turning into spaces.
  • This is a known backend bug linked to issue #2592.
  • Workarounds such as double-encoding the email were suggested.
  • The bug has been fixed in a newer version, and testing on PR #3863 or upgrading to the latest version was recommended.
  • The maintainer requested more context and testing feedback from you.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thanks for your understanding and contribution!

<!-- gh-comment-id:3498170994 --> @dosubot[bot] commented on GitHub (Nov 6, 2025): Hi, @dccarmo. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that in Better Auth v1.3.2, the `callbackURL` query parameter with an encoded email is decoded incorrectly on redirect, causing issues like `+` turning into spaces. - This is a known backend bug linked to issue #2592. - Workarounds such as double-encoding the email were suggested. - The bug has been fixed in a newer version, and testing on PR #3863 or upgrading to the latest version was recommended. - The maintainer requested more context and testing feedback from you. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - Otherwise, this issue will be automatically closed in 7 days. Thanks for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18363