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

Node-adapted app crashes on request if referenced ADDRESS_HEADER is missing #10284

Closed
Conduitry opened this issue Jun 29, 2023 · 2 comments · Fixed by #10285
Closed

Node-adapted app crashes on request if referenced ADDRESS_HEADER is missing #10284

Conduitry opened this issue Jun 29, 2023 · 2 comments · Fixed by #10285
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-node

Comments

@Conduitry
Copy link
Member

Conduitry commented Jun 29, 2023

Describe the bug

Making a request to a non-prerendered page of a Node-adapter application with ADDRESS_HEADER set to a header that's not present in the request crashes the application. This happens even if the user code does not use getClientAddress anywhere.

Reproduction

  1. Start with the default demo app
  2. Swap out the auto adapter for the Node adapter
  3. Build it with npm run build
  4. Start it with ADDRESS_HEADER=blah node build
  5. Run curl localhost:3000/sverdle

This crashes the server for me. Interestingly, curl localhost:3000 does not crash the server, presumably because that page is prerendered.

Logs

Error: Address header was specified with ADDRESS_HEADER=blah but is absent from request
    at Array.ssr (file:///.../build/handler.js:1198:9)

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 9 4900HS with Radeon Graphics
    Memory: 14.28 GB / 19.25 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.3.1
    Yarn: 1.22.19
    npm: 9.6.7
    pnpm: 8.6.3
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0 => 1.2.4
    @sveltejs/kit: ^1.20.4 => 1.21.0
    svelte: ^4.0.0 => 4.0.1
    vite: ^4.3.6 => 4.3.9

Severity

serious, but I can work around it

Additional Information

I think we should just move the check for the header referenced in ADDRESS_HEADER into the getClientAddress callback we pass back from the adapted output. We definitely don't want to crash the app. Another possibility would be to make that be an instant 500 without calling any of the underlying SvelteKit code (and without waiting for getClientAddress() to be called), but that doesn't seem quite necessary (maybe the user wants to handle that case!) and I'm not sure what a nice way to do that would be without duplicating SvelteKIt's error.html templating logic.

I'm working around this for now by simply using the appropriate headers directly - with my own fallbacks if they don't exist - rather than trying to use getClientAddress().

@Conduitry Conduitry added bug Something isn't working pkg:adapter-node p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. labels Jun 29, 2023
@Conduitry
Copy link
Member Author

I was looking at too many crazy things and my brain had stopped working. The check that the header is present is not inside the getClientAddress() call like the other XFF_DEPTH checks are. I'll amend my issue description above accordingly.

This is still a bad bug. It shouldn't crash the server if these headers are missing. IMO we should just move this check inside the getClientAddress() function, so that that will throw if it's missing, which will either get handled by the user code, or will result in a 500 from the server.

@Conduitry
Copy link
Member Author

On the other hand, I think it may very well make sense to make a zero/negative XFF_DEPTH value crash the server, since that's something that can be immediately determined at startup, and it's not going to be something that can bring down the server later. That would probably be a breaking change though, and we should think about whether there's other stuff (startup env var validation or otherwise) that we might want to do at the same time.

dummdidumm pushed a commit that referenced this issue Jun 30, 2023
…m a request (#10285)

This fixes #10284 by moving the check for the presence of the header specified in ADDRESS_HEADER inside the getClientAddress function. The old behavior is that non-prerendered requests without the appropriate header will instantly crash the server. The new behavior is that getClientAddress() will throw an exception, like with the other checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. pkg:adapter-node
Projects
None yet
1 participant