Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend-sdk: cookies set via SDK not valid for subdomains #699

Closed
2 tasks done
lfleischmann opened this issue Mar 27, 2023 · 3 comments · Fixed by #1251
Closed
2 tasks done

frontend-sdk: cookies set via SDK not valid for subdomains #699

lfleischmann opened this issue Mar 27, 2023 · 3 comments · Fixed by #1251
Labels
enhancement New feature or request

Comments

@lfleischmann
Copy link
Member

lfleischmann commented Mar 27, 2023

Checklist

  • I could not find a solution in the existing issues or docs.
  • I agree to follow this project's Code of Conduct.

Description

Cookies set by the SDK (i.e. set in response to reading the X-Auth-Token header in case of frontend and Hanko API running on different domains) are not valid for subdomains. If my frontend runs on yourapp.com and I have another API running at api.yourapp.com then the cookie will only be valid for yourapp.com but not the api subdomain. This is because we do not set the domain attribute on creating the cookie:

_setAuthCookie(token: string) {
    const secure = !!this.api.match("^https://");
    Cookies.set(this.authCookieName, token, { secure }); // <- no domain set
}

From MDN:

The Domain attribute specifies which hosts can receive a cookie. If the server does not specify a Domain, the browser defaults the domain to the same host that set the cookie, excluding subdomains. If Domain is specified, then subdomains are always included.

I think it is a viable scenario that users run another service on such a subdomain and want to use the JWT for authentication with said service as well.

Describe your ideal solution

Set the domain when creating the cookie:

_setAuthCookie(token: string) {
    const secure = !!this.api.match("^https://");
    Cookies.set(this.authCookieName, token, { secure , domain: "<DOMAIN>" }); // 
}

How to get the domain at this point:

  1. Determine from current location (not sure how to do this in reliable/robust manner) or
  2. Make it configurable and propagate via public configuration

Workarounds or alternatives

No response

Hanko Version

v0.5.0

Additional Context

No response

@lfleischmann lfleischmann added the enhancement New feature or request label Mar 27, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in Hanko Mar 28, 2023
@FlxMgdnz FlxMgdnz moved this from 🆕 New to 🔖 Ready in Hanko Mar 28, 2023
@github-actions
Copy link
Contributor

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Jul 27, 2023
@github-actions
Copy link
Contributor

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-project-automation github-project-automation bot moved this from 🔖 Up next to ✅ Recently closed in Hanko Aug 10, 2023
@lfleischmann lfleischmann reopened this Aug 10, 2023
@IgnisDa
Copy link
Contributor

IgnisDa commented Sep 19, 2023

@lfleischmann Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants