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

Url wrong protocol? #62

Open
m1212e opened this issue Jul 17, 2024 · 2 comments
Open

Url wrong protocol? #62

m1212e opened this issue Jul 17, 2024 · 2 comments

Comments

@m1212e
Copy link

m1212e commented Jul 17, 2024

Hi, no matter if I configure ORIGIN, PROTOCOL_HEADER or HOST_HEADER my load function gets the URL as HTTP not HTTPS.

My load function:

export const load: LayoutServerLoad = async ({ url, cookies, request }) => {
	console.log('url', url.toString());
	console.log('headers', request.headers);
};

My envs:

    environment:
      - HOST_HEADER=x-forwarded-host
      - PROTOCOL_HEADER=x-forwarded-proto
      - ORIGIN=https://staging.app.my.domain.de

My console output on request:

 url http://staging.app.my.domain.de/registration
 headers Headers {
   "host": "staging.app.my.domain.de",
   "user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0",
   "accept": "*/*",
   "accept-encoding": "gzip, deflate, br, zstd",
   "accept-language": "de-DE,en;q=0.5",
   "cache-control": "no-cache",
   "cookie": "paraglide:lang=en",
   "dnt": "1",
   "pragma": "no-cache",
   "referer": "https://staging.app.my.domain.de/",
   "sec-fetch-dest": "empty",
   "sec-fetch-mode": "cors",
   "te": "trailers",
   "priority": "u=4",
   "sec-fetch-site": "same-origin",
   "sec-gpc": "1",
   "x-forwarded-for": "172.23.0.1",
   "x-forwarded-host": "staging.app.my.domain.de",
   "x-forwarded-port": "443",
   "x-forwarded-proto": "https",
   "x-forwarded-server": "f5c2bc4386a1",
   "x-real-ip": "172.23.0.1",
 }

Whats the problem here?

@m1212e
Copy link
Author

m1212e commented Jul 17, 2024

Also my adapter is configured like this:

adapter: adapter({
			dynamic_origin: true,
		}),

@ckiee
Copy link
Contributor

ckiee commented Oct 22, 2024

update: probably fixed by 8140529

I ended up just doing

const requestFixupHandle: Handle = async ({ event, resolve }) => {
    // yes this is also still necessary . silly shit. this one is for the redirect url
    if (env.IS_HTTPS == "1")
        event.url = new URL(event.url.toString().replace(/^http:/, "https:"))

    // authjs is a naughty beast and uses this other url (event.request.url)
    // which is Request#url which is readonly.. use some hax
    event.request = new Request(event.url, {
        method: event.request.method,
        headers: event.request.headers,
        body: event.request.body,
        referrer: event.request.referrer,
        referrerPolicy: event.request.referrerPolicy,
        mode: event.request.mode,
        credentials: event.request.credentials,
        cache: event.request.cache,
        redirect: event.request.redirect,
        integrity: event.request.integrity,
        //@ts-ignore
        duplex: event.request.duplex
    });

    return resolve(event);
};

hope it helps you proceed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants