mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 00:38:39 +09:00
Issue #2451 - Send referrer headers with CORS preflight requests.
This is dependent on referrer policy. Fixes #2451
This commit is contained in:
parent
bd723aac28
commit
79b4c36ef8
1 changed files with 22 additions and 0 deletions
|
|
@ -7,6 +7,8 @@
|
|||
#include "mozilla/LinkedList.h"
|
||||
|
||||
#include "nsCORSListenerProxy.h"
|
||||
|
||||
#include "nsQueryObject.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "HttpChannelChild.h"
|
||||
|
|
@ -1507,6 +1509,9 @@ nsCORSListenerProxy::StartCORSPreflight(nsIChannel* aRequestChannel,
|
|||
method, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
RefPtr<nsIHttpChannel> reqCh = do_QueryObject(aRequestChannel);
|
||||
RefPtr<nsIHttpChannel> preCh = do_QueryObject(preHttp);
|
||||
|
||||
nsTArray<nsCString> preflightHeaders;
|
||||
if (!aUnsafeHeaders.IsEmpty()) {
|
||||
for (uint32_t i = 0; i < aUnsafeHeaders.Length(); ++i) {
|
||||
|
|
@ -1535,6 +1540,23 @@ nsCORSListenerProxy::StartCORSPreflight(nsIChannel* aRequestChannel,
|
|||
rv = preflightChannel->SetNotificationCallbacks(preflightListener);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (reqCh && preCh) {
|
||||
// Per https://fetch.spec.whatwg.org/#cors-preflight-fetch step 1, the
|
||||
// request's referrer and referrer policy should match the original request.
|
||||
// Note that RFC 9110 says we SHOULD NOT send referrers on insecure requests
|
||||
// which CORS preflights by definition are, so there's a conflict here, but
|
||||
// since this is expected behaviour in mainstream implementations, we get and
|
||||
// send the referrer on CORS preflights here. See issue #2451
|
||||
uint32_t referrerPolicy = nsIHttpChannel::REFERRER_POLICY_UNSET;
|
||||
rv = reqCh->GetReferrerPolicy(&referrerPolicy);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIURI> requestReferrerURI;
|
||||
rv = reqCh->GetReferrer(getter_AddRefs(requestReferrerURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = preCh->SetReferrerWithPolicy(requestReferrerURI, referrerPolicy);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// Start preflight
|
||||
rv = preflightChannel->AsyncOpen2(preflightListener);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue