Get set-cookie value from the response header angular - javascript

I am trying to get the set-cookie from Response Headers.
The reason of doing this is set-cookie is not setting cookie and showing the warning This attempt to set a cookie via a Set-Cookie header was blocked because its Domain attribute was invalid with regards to the current host url. Attached is the screenshot
Now I thought to get the set-cookie value from Response Header by the following code
But it always returns null for set-cookie but return the value fo expires.
Please anyone can guide how to fix this issue or how can I get the value of set-cookie from Response Header.
Any help will be highly appreciated.
Thanks

According to developer.mozilla.org set-cookie is a forbidden response header name. You cannot read it using browser-side JavaScript
Browsers block frontend JavaScript code from accessing the Set Cookie header, as required by the Fetch spec, which defines Set-Cookie as a forbidden response-header name that must be filtered out from any response exposed to frontend code.

Related

How to read "Set-cookie" from response header in React

I can not read my cookie from the response header marked with the Set-Cookie key in my browser.
I can read and get everything in the response header except for the Set-Cookie.
My cookie is in the response header in my browser but I can not get or read it in my React project.
I noticed that it is not possible to get Set-Cookie in JavaScript.
I even have an extra tab called Cookies in my browser in the Inspect section and on the Network tab, in addition to the Headers, Payload tabs, etc., that contain my cookies.
I want to know how to save my cookie after logging in?
I use axios and Redux.
Thanks to those who help me!

Cookies are not included when using withCredentials in XMLHttpRequest

Here is my scenario:
I am making an ajax request from foo.com to api.bar.com. In the response, it sets some cookies using Set-Cookie header. The domain on the set-cookie header is .bar.com. I am using all steps listed here How to make XMLHttpRequest cross-domain withCredentials, HTTP Authorization (CORS)?
I am able to see and verify (using Chrome extension EditThisCookie) that cookies are being set properly for domain .bar.com.
According to my understanding, when I make an ajax request (using withCredential:true) to cdn.bar.com, , it should include the cookies that were set earlier for domain .bar.com.
These cookies do not get included in the request, I can see it in fiddler. What am I missing here?
EDIT
Cookies DO get included in the request header If I make a request to cdn.bar.com from an origin app.bar.com. The problem only appears when it's called from a different origin foo.com.
The issue was with the SameSite restriction of the cookie. If I change the it from lax to No Restriction then it works fine.

Here Javascript CORS header missing

I use the Javascript API within an Angular Project. I'm using HTTPS connection. It all worked the last months but since last week, I don't get any Tiles loaded.
To a lot of requests, I get the response:
403 "No Access-Control-Allow-Origin header is present on the requested resource."
Sometimes the request is successful and I get a Tile and the correct cors header, but that is only 1 of 20 requests I think.
Did I miss some API changes? Is this only on my side or are there any others affected?
You can always Enable CORS by returning correct headers
Access-Control-Allow-Headers string
Access-Control-Allow-Methods string
Access-Control-Allow-Origin string
For more details -
https://developer.here.com/documentation/tour-planning/api-reference-swagger.html
https://developer.here.com/olp/documentation/vector-tiles-api/dev_guide/topics/http-response-codes.html

I'm not using the wildcard in Access-Control-Allow-Origin, but Chrome says that I am

I'm running an ionic application using ionic serve on port 8080. I do understand the preflight process and I believe I'm getting the right response:
Still, I'm getting this error:
Failed to load https://bla.bla: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:8080' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
Then, the real request (GET) is not being sent.
What is even weirder is that just before this one request, I'm able to send a POST to the same server. The response headers are the same. The only difference in the request is that the Access-Control-Request-Headers is content-type instead of authentication
Any ideas?
Finally found the answer and it was my fault, not a chrome bug.
Thing is, some time ago I tried using this extension:
https://chrome.google.com/webstore/detail/cors-toggle/jioikioepegflmdnbocfhgmpmopmjkim?hl=en
And it didn't work for my needs, but I forgot to uinstall it. Turns out it was having some kind of conflict, since it seems to add an "Access-Control-Allow-Origin: *" header for every response. Thus it would conflict in a request with credentials (I'm guessing the Authentication header does that, not sure why tbh).
Anyway, after I uninstalled it, it's now working fine.

Can you set the Host header using fetch API

I have a reverse proxy server, which redirects you to different services depending on the Host header.
However when making requests to this server using a browser, the Host is always set to the domain name in the URL. I tried:
fetch("http://foo.com", {"headers":{"Host":"bar.foo.com"}})
But it doesn't work
Host is one of the forbidden header names:
A forbidden header name is an HTTP header name that cannot be modified programmatically.
It won't work. You cannot set the forbidden Headers on making the requests through browsers.
You can get the list of forbidden headers here - https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
Similar answers here:
Ajax request: Refused to set unsafe header
Not able to set HTTP Host header on $.ajax request

Categories