Hi. Passwordless Recipe. Why is the magic link of ...
# support-questions
p
Hi. Passwordless Recipe. Why is the magic link of the form /auth/verify?rid=passwordless&preAuthSessionId=# ? i.e. Why is the linkCode an anchor and not a query param? I cannot manage to use it this way and I don't understand why it is like this.
r
HI @User - it's not a query param due to security best practices. Query params tend to get saved in the browser history.
What issues are you having with the current format?
p
The OTP side is fine, my issue is with the magic link. Because
POST /{apiBasePath}/signinup/code/consume
requires
preAuthSessionId
(which I have) but also
linkCode
, which I cannot extract from the url as it is an anchor.
r
You can extract it using location.hash.substr(1)
p
ok. I wanted to do this in SvelteKit's load function, which is SSR, so I cannot access window nor document. I'll just get it from window.location.hash... after the page is mounted
r
I see.
Yea.. you will have to do it post mount.
Im surprised that it doesn't give you access to the hash part.. interesting
p
apparently it's not possible: https://github.com/sveltejs/kit/issues/1676
r
I see.. well.. There is one hack you can do -> in the function you have written to send an email (on the backend), you can modify the url to remove the code from the hash and put it as a query param. And then you can consume it in SSR
p
yes I was typing that a moment ago, and wanted to propose if params: CreateAndSendCustomEmailParameters could also have a link_code property
but that defeats the purpose of your security best practices
r
Yea..
But you can still modify the link anyway.
Since it's just a string
p
I don't see how the link code can be used for an attack though, it's auto generated for each time right?
ok, I might do that
r
Yes. There are more security implications to this. Perhaps @User can shed some light.
p
the security implication is that the query params are automatically sent to the server and can be potentially accessed/logged by proxies along the way and the also tend to appear in server logs. This isn't a problem in this specific case, since they are single use codes and we are sending them to the server by default. Still, it's good practice to put secrets into the hash, so the client can choose to use it as opposed to it being automatically sent to the server.
Also, in a customized implementation, where the user has to do something before using their link codes it could be an issue, where potentially unused codes appear in server logs.
Plus this way we leave the option open to do some magic on the client side with the code.
p
ok, thanks guys
Q: the code_life_time is just for the OTP code or also for the magic link?
r
For both.
p
great