Do not unconditionally inject ?error into error redirect URL; allow custom error URL builder #1663

Open
opened 2026-03-13 08:54:30 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @danielo515 on GitHub (Aug 8, 2025).

Originally assigned to: @frectonz on GitHub.

Summary

When Better Auth redirects to an error page, it unconditionally appends an error search parameter to the provided error URL. This causes conflicts when the application already includes its own search params (e.g. a title or message param) or when a different param name/format is desired.

As a result, the final URL ends up with unexpected params or key collisions (e.g. ...?title=Invalid+invite?error=Some+message), which can override or conflict with the app’s intended messaging / UX.

Steps to Reproduce

  1. Configure Better Auth to redirect to a custom error page with an existing query param, for example:
    • Error URL: /error?title=Invalid%20invite
  2. Trigger an auth error that causes Better Auth to redirect to the error URL.
  3. Observe that Better Auth appends ?error=<message>, even if the URL already contains search params.

Actual Behavior

The library appends an error query parameter unconditionally to the error URL, leading to duplicate/conflicting search params.

Expected Behavior

  • Either check the URL’s existing search params and merge safely without overriding (and ideally without enforcing the specific error key name),
  • Or provide a way to fully customize the error URL construction so apps can decide how to represent the error information.

Proposed Solutions

  1. Guard/merge logic:

    • If the provided error URL already contains a query string, merge the new params without overwriting existing keys.
    • Only add the error param if it does not already exist.
    • Consider allowing a custom key name so consumers aren’t forced to use error.
  2. Extensibility hook (preferred):

    • Add a configuration option like errorUrlBuilder: (error: ErrorLike, baseUrl: URL | string) => string.
    • Better Auth would call this function with the error and the base error URL, letting the app return the final redirect URL.
    • This avoids library-level assumptions and enables full control (i18n, structured JSON in a param, fragments, etc.).

If a configuration already exists that covers this use case, documentation/examples would be appreciated.

Thanks for considering this!

Originally created by @danielo515 on GitHub (Aug 8, 2025). Originally assigned to: @frectonz on GitHub. ## Summary When Better Auth redirects to an error page, it unconditionally appends an `error` search parameter to the provided error URL. This causes conflicts when the application already includes its own search params (e.g. a `title` or `message` param) or when a different param name/format is desired. As a result, the final URL ends up with unexpected params or key collisions (e.g. `...?title=Invalid+invite?error=Some+message`), which can override or conflict with the app’s intended messaging / UX. ## Steps to Reproduce 1. Configure Better Auth to redirect to a custom error page with an existing query param, for example: - Error URL: `/error?title=Invalid%20invite` 2. Trigger an auth error that causes Better Auth to redirect to the error URL. 3. Observe that Better Auth appends `?error=<message>`, even if the URL already contains search params. ## Actual Behavior The library appends an `error` query parameter unconditionally to the error URL, leading to duplicate/conflicting search params. ## Expected Behavior - Either check the URL’s existing search params and merge safely without overriding (and ideally without enforcing the specific `error` key name), - Or provide a way to fully customize the error URL construction so apps can decide how to represent the error information. ## Proposed Solutions 1. Guard/merge logic: - If the provided error URL already contains a query string, merge the new params without overwriting existing keys. - Only add the `error` param if it does not already exist. - Consider allowing a custom key name so consumers aren’t forced to use `error`. 2. Extensibility hook (preferred): - Add a configuration option like `errorUrlBuilder: (error: ErrorLike, baseUrl: URL | string) => string`. - Better Auth would call this function with the error and the base error URL, letting the app return the final redirect URL. - This avoids library-level assumptions and enables full control (i18n, structured JSON in a param, fragments, etc.). If a configuration already exists that covers this use case, documentation/examples would be appreciated. Thanks for considering this!
GiteaMirror added the enhancement label 2026-03-13 08:54:30 -05:00
Author
Owner

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

Hi, @danielo515. 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 Better Auth appends an error query parameter to error redirect URLs without checking for existing parameters, causing conflicts.
  • You suggested safer query parameter merging or a customizable error URL builder function to avoid key collisions.
  • No further comments or updates have been provided since your initial report.
  • The issue remains unresolved and open for discussion.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I do not hear back within 7 days, this issue will be automatically closed.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Nov 10, 2025): Hi, @danielo515. 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 Better Auth appends an `error` query parameter to error redirect URLs without checking for existing parameters, causing conflicts. - You suggested safer query parameter merging or a customizable error URL builder function to avoid key collisions. - No further comments or updates have been provided since your initial report. - The issue remains unresolved and open for discussion. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. - If I do not hear back within 7 days, this issue will be automatically closed. Thank you for your understanding and contribution!
Author
Owner

@danielo515 commented on GitHub (Nov 11, 2025):

This issue is still relevant. I would love to hear something from the team on what they think at least

@danielo515 commented on GitHub (Nov 11, 2025): This issue is still relevant. I would love to hear something from the team on what they think at least
Author
Owner

@ping-maxwell commented on GitHub (Nov 12, 2025):

This issue is still relevant. I would love to hear something from the team on what they think at least

Sounds good.

@ping-maxwell commented on GitHub (Nov 12, 2025): > This issue is still relevant. I would love to hear something from the team on what they think at least Sounds good.
Author
Owner

@dosubot[bot] commented on GitHub (Feb 11, 2026):

Hi, @danielo515. 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 Better Auth appends an error query parameter to redirect URLs without checking for existing parameters, causing conflicts.
  • You requested safer merging of query parameters or a customizable error URL builder to avoid key collisions.
  • The issue remains open and unresolved, with you and @ping-maxwell confirming its ongoing relevance.
  • No recent updates or maintainer input have been provided yet.

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.
  • If I do not hear back within 7 days, this issue will be automatically closed.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Feb 11, 2026): Hi, @danielo515. 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 Better Auth appends an `error` query parameter to redirect URLs without checking for existing parameters, causing conflicts. - You requested safer merging of query parameters or a customizable error URL builder to avoid key collisions. - The issue remains open and unresolved, with you and @ping-maxwell confirming its ongoing relevance. - No recent updates or maintainer input have been provided yet. **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. - If I do not hear back within 7 days, this issue will be automatically closed. Thank you for your understanding and contribution!
Author
Owner

@danielo515 commented on GitHub (Feb 12, 2026):

The summary is correct, and this is indeed still a problem.

@danielo515 commented on GitHub (Feb 12, 2026): The summary is correct, and this is indeed still a problem.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1663