Skip to content

Allow credentials to be forwarded during HTTP requests to API server #1510

@stouset

Description

@stouset

Summary

We are trying to run both shlink-web-client and shlink behind an authenticating reverse proxy. Authentication state is indicated through a cookie. If the cookie isn't present, the client is redirected to an authentication page. If the cookie is present (and contains valid session credentials), the request is transparently sent to the backend.

With shlink-web-client, requests to the API server include the API key but are not configured to send other forms of browser credentials, so they are redirected to an authentication page (which obviously the web client has no idea how to handle). We need the cookie to be sent when making these cross-origin requests.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Credentials

This takes two parts. One, the API server needs to set the Access-Control-Allow-Credentials HTTP header to true and the Access-Control-Allow-Origin to explicitly include the Origin of the web client. This tells the client browser that it can send credentials like cookies for these CORS requests. Luckily, we can instruct our authenticating proxy to force these headers to be set. I don't think there's a convenient mechanism in place to have shlink send the appropriate Access-Control-Allow-Origin header at the moment as it would require the backend to know the origin of the client in advance.

The other half is something we can't fake on our end with our authenticating proxy, unfortunately, and it's instructing the JS HTTP client that it should send credentials along with requests. From a cursory look at the code, I believe this will require a change to shlink-js-sdk to set credentials: "include" when the fetch client is constructed. I believe this should be safe to roll out generally, but I understand if you want to have it be an option exposed in the web-client's server configuration UI.

Use case

Sending stored HTTP credentials along with web-client requests to the API server is necessary in order to allow shlink-web-client to successfully communicate with a shlink API server behind an authenticating proxy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions