mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-15 08:53:07 +09:00
Issue #1975 - Implement Origin header CSRF mitigation.
Backported from Mozilla bug 446344.
This commit is contained in:
parent
3e6cbc6af3
commit
faa778ec9d
6 changed files with 82 additions and 15 deletions
|
|
@ -1398,22 +1398,10 @@ HttpBaseChannel::SetReferrerWithPolicy(nsIURI *referrer,
|
|||
referrer = referrerGrip.get();
|
||||
}
|
||||
|
||||
//
|
||||
// block referrer if not on our white list...
|
||||
//
|
||||
static const char *const referrerWhiteList[] = {
|
||||
"http",
|
||||
"https",
|
||||
"ftp",
|
||||
nullptr
|
||||
};
|
||||
match = false;
|
||||
const char *const *scheme = referrerWhiteList;
|
||||
for (; *scheme && !match; ++scheme) {
|
||||
rv = referrer->SchemeIs(*scheme, &match);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// Enforce Referrer whitelist
|
||||
if (!IsReferrerSchemeAllowed(referrer)) {
|
||||
return NS_OK; // kick out....
|
||||
}
|
||||
if (!match) return NS_OK; // kick out....
|
||||
|
||||
//
|
||||
// Handle secure referrals.
|
||||
|
|
@ -2844,6 +2832,24 @@ HttpBaseChannel::AddCookiesToRequest()
|
|||
SetRequestHeader(nsDependentCString(nsHttp::Cookie), cookie, false);
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool
|
||||
HttpBaseChannel::IsReferrerSchemeAllowed(nsIURI *aReferrer)
|
||||
{
|
||||
NS_ENSURE_TRUE(aReferrer, false);
|
||||
|
||||
nsAutoCString scheme;
|
||||
nsresult rv = aReferrer->GetScheme(scheme);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
if (scheme.EqualsIgnoreCase("https") ||
|
||||
scheme.EqualsIgnoreCase("http") ||
|
||||
scheme.EqualsIgnoreCase("ftp")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
HttpBaseChannel::ShouldRewriteRedirectToGET(uint32_t httpStatus,
|
||||
nsHttpRequestHead::ParsedMethodType method)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue