Safari does not include cookies in JSONP requests
See original GitHub issueHow to reproduce these conditions
Sample name or URL where you found the bug
firebase/functions-samples/spotify-auth, but the other auth examples may be affected too.
Failing Function code used (including require/import commands at the top)
spotify-auth/functions/index.js
const functions = require('firebase-functions');
const cookieParser = require('cookie-parser');
[...]
exports.token = functions.https.onRequest((req, res) => {
try {
cookieParser()(req, res, () => {
console.log('Received verification state:', req.cookies.state);
console.log('Received state:', req.query.state);
if (!req.cookies.state) {
throw new Error('State cookie not set or expired. Maybe you took too long to authorize. Please try again.');
} else if (req.cookies.state !== req.query.state) {
throw new Error('State validation failed');
}
[...]
Steps to set up and reproduce
Setup the Spotify-auth example and use Safari (Version 12.0 14606.1.36.1.9) to test it.
Debug output
Errors in the console logs
State cookie not set or expired. Maybe you took too long to authorize. Please try again.
The req.cookies
object is empty.
Expected behavior
No exception.
Actual behavior
As far as I can see, Safari does not include cookies in JSONP request. It works fine in Chrome though.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8
Top Results From Across the Web
Safari not include COOKIE to second CORS request
Ok - after loooong analysing requests finally I found the problem - in login response the server set in Set-Cookie header the cookie...
Read more >Accessing cookie not possible on d… | Apple Developer Forums
We perform login to backend server using normal ajax call and in the response the Cookie is read and send in subsequent requests....
Read more >XMLHttpRequest.withCredentials - Web APIs | MDN
XMLHttpRequest responses from a different domain cannot set cookie values for their own domain unless withCredentials is set to true before ...
Read more >HTTP cookie - Wikipedia
HTTP cookies are small blocks of data created by a web server while a user is browsing a website and placed on the...
Read more >Using Postman Interceptor
You can capture requests from your browser and cookies from any domain to use ... [macOS only] Install NodeJS - If Postman detects...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I was finally able to solve this after poking around multiple tickets/PRs.
My solution ended up using code from: #826 #849 #852
The basic rundown:
req.cookies.state
to bereq.cookies.__session
across the files as seen in these updated filesres.cookie
object to be(note we changed
res.cookies('state'...
to beres.cookies('__session'...
from step 1), also note this commentNote, I don’t know if this is the secure/best/optimal way. I attempted each of these on their own and then started combining them to see what worked.
@kevinguebert You’re a godsend!