Firefox does not accept cookies sent with XHR CORS requests

I am currently in the process of creating a login page on the domain "example.com" that makes an Ajax request to the domain "other_domain.com." If the credentials are valid, this request will return a session cookie. My goal is to then redirect to the "other_domain.com" site and be logged in.

My solution works well with IE11, Edge, and Chrome, but I have encountered a problem with Firefox. It seems that Firefox does not set the returned cookie when redirecting to the "other_domain.com" site.

Here is the code for the ajax request:

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open('POST', 'https://other_domain.com/login', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
    if (this.status == 200 && this.readyState == 4) {

        window.location.replace("https://other_domain.com/app");

    }
};
xhr.send(JSON.stringify(payload));

I am able to see that the OPTIONS request succeeds and the AJAX post returns 200 OK on all browsers if the credentials are correct.

The cookie that is returned has the following values:

CreationTime: "Fri, 28 Sep 2018 12:48:49 GMT"
Domain: "other_domain.com"
Expires: "Session"
HostOnly: true
HttpOnly: true
LastAccessed: "Fri, 28 Sep 2018 12:48:49 GMT"
Path: "/"
Secure: true
sameSite: "Lax"

Additional information after being flagged as duplicate:

In the developer console, I can see that both the OPTIONS and POST requests from the provided code return the following headers:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://example.com

I also notice the Set-Cookie header with the correct value in the response in Firefox, but unfortunately, the cookie is not set after the redirect to other_domain.com. Even though my Firefox settings allow for third-party cookies and site data to be accepted at all times.

Answer №1

I encountered a similar problem recently. Check the Set_Cookie function and see if it includes the SameSite=lax attribute. If it does, make sure to set that attribute to None when setting the cookie on the server. Within the .NET framework, when you're creating a cookie, you can choose between lax, strict, or none for this option.

Link to more information

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Develop a custom dropdown menu using JavaScript

I've been working on creating a dropdown menu that appears after selecting an option from another dropdown menu. Here's the HTML code I'm using: <br> <select id ="select-container" onchange="addSelect('select-container') ...

I am attempting to secure a webpage with a password using JavaScript

I've been working on adding password protection to my webpage at , with the goal of allowing users to enter the password once per session. However, I've encountered an issue: if a user cancels out of the initial prompt or enters the wrong passwor ...

AngularJS: default option not being selected in dropdown menus

I need assistance with a dropdown list issue. See the code snippet below: My Controller (function(angular) { 'use strict'; angular.module('ngrepeatSelect', []) .controller('ExampleController', ['$scope', functi ...

Utilizing Ajax to serialize or transfer JSON objects

I have received a Json object and I am looking to extract the data using JavaScript. Specifically, I need help with looping through fields and extracting the data. def For_Sale_Listing(request,id): try: listing = Listing.objects.filter(pk=id) ...

Footer placement not aligning at the bottom using Bootstrap

I'm having trouble getting my footer to stay at the bottom of my website without it sticking when I scroll. I want it to only appear at the bottom as you scroll down the webpage. Currently, the footer is positioned beneath the content on the webpage. ...

An error occurred when attempting to use the getDoc() function from Firebase within Next.js: TypeError - reading 'map' on properties of undefined

Hello everyone at StackOverflow, I ran into a problem while attempting to use .map() on a getDoc() constant in my Next.js application. The error message I'm getting is: "TypeError: Cannot read properties of undefined (reading 'map')". As a n ...

Error in Bootstrap detected by Mozilla Developer Tools

Recently, I decided to experiment with Bootstrap 4 and created a simple HTML file: <!DOCTYPE html> <html lang="en"> <head> <title>Template</title> <meta charset="utf-8"> <meta name="view ...

Display icon within ng-bind-html when the value is not true

Is there a way to integrate a fontawesome icon into ng-bind-html on ui-select based on a boolean value? <span ng-bind-html="project.IsActive == false && <i class="fa fa-ban" aria-hidden="true"></i> | highlight: $select.search">& ...

Utilize Google Chrome Developer Tools to interact with the "Follow" buttons on the webpage by clicking on them

https://i.stack.imgur.com/W32te.png Here is the script I am currently using: document.querySelectorAll('.components-button components-button-size-mini components-button-type-orange desktop components-button-inline').forEach(btn => btn.click() ...

Repeating a post retrieved from a query in the function.php file

Looking to implement an AJAX post filter based on category? Check out this resource I found: The challenge I'm facing is customizing the post output from function.php. Currently, it looks like this: echo '<h2>' . $query->post-> ...

Sending AJAX data to the Controller for parsing and receiving the response

Check out this AJAX call that communicates with the controller: $.ajax({ type: "GET", url: '@Url.Action("getChat", "Chat")', success: function (data) { alert(data); $("#data").html(data); }, error:{ ...

Ensure that the input button for uploading is only accessible when checked and is marked as

Most of my previous questions have been about input boxes and SQL, as I am still in the learning process. Any help is greatly appreciated. My current question revolves around displaying a button to upload an image using PHP (although for this example, I w ...

Issue with Vue.js where the v-if directive placed inside a v-for loop does not properly update when

I want to dynamically show elements from an array based on boolean values. However, I am facing an issue where the element does not disappear even after the boolean value changes. <li v-for="(value, index) in list"> <span> {{ value[0] }} & ...

Establishing a default selection for a react dropdown menu filled with data retrieved from an API request

class Select extends React.PureComponent { constructor(props) { super(props) this.state = { value: this.props.initialValue } this.handleChange = this.handleChange.bind(this) } handleChange(e) { e.persist() ...

How can we reset multiple selected values (mui chips) in a React Material-UI Autocomplete field when changing the value in a different field?

Is there a way to clear the mui-chips in Material UI Autocomplete TextField when the value in another field is changed? I have been struggling with clearing the subtype value when the Type value changes. Although I can update the drop-down options based on ...

Changing the formatting of a buffer from int8 to float32 using JavaScript

Within a buffer, I have a series of bytes that were read from a file. I am looking to convert these bytes into a sequence of float32 values without having to copy them to a new buffer, given that each data block is approximately 15KB in size. I have come a ...

Tips for utilizing state and city dropdown menus in JavaScript multiple times without interfering with other dropdowns

Currently, I am utilizing CodeIgniter to create a dynamic dropdown functionality. The setup involves four select country dropdowns where the state options will populate based on the selected country, and once a state is chosen, the corresponding city optio ...

Identifying the class name of SVGAnimatedString

While working on creating an SVG map, I encountered an issue where the functions triggered by hovering over 'g' elements were not functioning as expected. In order to troubleshoot this problem, I decided to check for any issues with the class nam ...

What are some ways to implement dangerouslySetInnerHTML in conjunction with read-more-react from npm?

Is there a way to include dangerouslySetInnerHTML in a text field without receiving an error? <ReadMoreReact text={yourTextHere} min={minimumLength} ideal={idealLength} max={maxLength} readMoreText={read ...

When using nodejs with sqlite3, the first callback parameter returns the class instance. How can this be resolved in order to prevent any issues?

Exploring a TypeScript class: class Log { public id: number; public text: string; construct(text: string){ this.text = text; } save(){ db.run( `insert into logs(text) values (?) `, this.text, ...