question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSRing sites that make requests to external domains where cookies are needed

See original GitHub issue

Starting here @web-mech brings up a use case where SSR didn’t work.

Essentially, his app made requests to firebase. This requests won’t have the right cookie/auth privileges.

This issue is to discuss possible solutions, work arounds, or warnings we could add to make this situation better.

A few ideas off the top of my head:

Allow some type of mapping from cookie to domain to cookie.

I don’t think would really work practically, but perhaps if we had something like:

{
  "ABC": { "firebase.com": "DEF"}
}

We would be able to know session “ABC” should use “DEF” cookie if any requests get made to firebase.

I don’t think this is practical or really possible. A browser won’t send its cookies for firebase to a different server. I’d have to learn more about firebase’s auth strategy to know if there’s any other work around.

Zone.ignore

We should be able to ignore this piece of code. @matthewp what does that look like?

Warning if XHR to other domains

If the XHR request being made doesn’t match the origin of the SSR request, we should let people know that the XHR request might not be made with the right cookies.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
marshallswaincommented, Nov 19, 2016

@matthewp and I also enabled the auth configuration as CLI params, so @web-mech should be able to enable authenticated SSR by adding the --auth-cookie and --auth-domains flags to the develop script in the package.json of a DoneJS app. The done-serve module will probably have to be updated for it to work.

1reaction
marshallswaincommented, Nov 19, 2016

The auth config setting of done-ssr is a step in this direction will already allow this. It currently only works with JWTs in Authorization headers, but I think it could be lightly tweaked to work with session ids placed into new cookies. It basically works like this:

ssr with auth

❶ The client authenticates directly with the API server, which is Firebase in this case. ❷ The API server responds with a token or a cookie. If it’s a cookie, it can’t be an http-only cookie. It has to be readable by the client. ❸ The client reads the contents of that cookie and creates a cookie named firebase-jwt for the SSR server’s domain. ❹ Upon refresh or page load, the cookie gets sent to the SSR server. ❺ The SSR server copies the auth data from the firebase-jwt cookie into requests destined for the API server. The destination is specified in DoneSSR’s auth config, which needs both a cookie name and a domains array. (Since the current version was setup for JWT auth on the Authorization header of requests, we couldn’t take advantage of cookies automatically going out on requests to specific domains) This is the part that could be tweaked so that the server just adds a cookie on the fly. The current version is also limited to a single API server only due to the auth config syntax. ❻ The API server, having received an authenticated request, responds with data. ❼ The SSR server assembles the page with the authenticated data and sends it to the client.

This whole process is already working for any server that allows auth using the Authorization header. Feathers does this, and I believe Firebase does, too, so this should already work for Firebase, but not for cookie/session based API servers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using HTTP cookies - MDN Web Docs
Creating cookies. After receiving an HTTP request, a server can send one or more Set-Cookie headers with the response.
Read more >
How to create cookie with external domain? - Stack Overflow
The cookie is a third-party cookie becuase the domain you're at (www.someotherdomain.com) differs from the domain the request is sent to (www.example.com).
Read more >
SameSite cookies explained - web.dev
Learn how to mark your cookies for first-party and third-party usage with the SameSite attribute. You can enhance your site's security by ...
Read more >
Everything You Need to Know About Cookies for Web ...
The server checks for your session using your session id, then returns data for your request.
Read more >
Cookies, document.cookie - The Modern JavaScript Tutorial
Cookies are small strings of data that are stored directly in the browser. They are a part of the HTTP protocol, defined by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found