You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Describe the bug
The server middleware doesn't add in the page request's Authorization header when fetching the same domain. This means that a site relying on the Authorization header will work when the client uses fetch, but will break when doing SSR on a page.
To Reproduce
Here's an example using express and express-basic-auth with the sapper template.
In src/server.js:
importsirvfrom'sirv';importexpressfrom'express';importcompressionfrom'compression';importbasicAuthfrom'express-basic-auth';import*assapperfrom'@sapper/server';const{PORT,NODE_ENV}=process.env;constdev=NODE_ENV==='development';conststaticUserAuth=basicAuth({users: {'username': 'password'},challenge: true})express()// You can also use Express.use(compression({threshold: 0}),sirv('static',{ dev }),staticUserAuth,sapper.middleware()).listen(PORT,err=>{if(err)console.log('error',err);});
You may also need to remove the service worker to stop it from interfering with the authentication process. The repo I used can be found here.
After logging in with the username username and the password password, if you click the hyperlink to the blog page, the content loads as expected because the browser adds the Authorization header because the request is for the same domain.
However, if you refresh /blog to perform ssr then it will display a 500 error because the server does not send an Authorization header to blog.json.
Expected behavior
The server middleware should send the Authorization header when the domain of its initial request matches the domain of the URL being fetched.
Additional context
I'm developing a web app using Firebase, and making use of the service worker to inject an Authorization header with the logged in user's authentication ID Token. This then gets verified by some middleware on the server. This approach means I don't have to deal with session cookies and keeping them in sync with Firebase auth and also negates the need for CSRF tokens. However, the server throws away the Authorization header at the moment, making it impossible for me to use ssr for authenticated routes.
The text was updated successfully, but these errors were encountered:
cyderize
changed the title
Authorization header doesn't get sent by server fetch
Authorization header doesn't get (automatically) sent by server fetch
Sep 9, 2019
Describe the bug
The server middleware doesn't add in the page request's Authorization header when fetching the same domain. This means that a site relying on the Authorization header will work when the client uses fetch, but will break when doing SSR on a page.
To Reproduce
Here's an example using
express
andexpress-basic-auth
with the sapper template.In
src/server.js
:In
src/routes/blog/[slug].svelte
, change line 5:You may also need to remove the service worker to stop it from interfering with the authentication process. The repo I used can be found here.
After logging in with the username
username
and the passwordpassword
, if you click the hyperlink to the blog page, the content loads as expected because the browser adds the Authorization header because the request is for the same domain.However, if you refresh
/blog
to perform ssr then it will display a 500 error because the server does not send an Authorization header toblog.json
.Expected behavior
The server middleware should send the Authorization header when the domain of its initial request matches the domain of the URL being fetched.
Additional context
I'm developing a web app using Firebase, and making use of the service worker to inject an Authorization header with the logged in user's authentication ID Token. This then gets verified by some middleware on the server. This approach means I don't have to deal with session cookies and keeping them in sync with Firebase auth and also negates the need for CSRF tokens. However, the server throws away the Authorization header at the moment, making it impossible for me to use ssr for authenticated routes.
The text was updated successfully, but these errors were encountered: