firebase / firebase/functions-samples

Safari does not include cookies in JSONP requests

Open
#511 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.2k
Forks
3.8k
Avg merge
3d 23h
Merged PRs (30d)
1

Description

### How to reproduce these conditions

**Sample name or URL where you found the bug**

[firebase/functions-samples/spotify-auth](https://github.com/firebase/functions-samples/tree/Node-8/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](https://github.com/firebase/functions-samples/blob/Node-8/spotify-auth/functions/index.js#L62)

```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](https://console.firebase.google.com/project/_/functions/logs?search=&severity=DEBUG)**

`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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.