mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-06 07:17:30 +09:00
Issue #2402 - Factor out code to set WorkerPrivate CSP from headers. https://bugzilla.mozilla.org/show_bug.cgi?id=1337543
This commit is contained in:
parent
971fc4b838
commit
37d4df19a8
3 changed files with 58 additions and 42 deletions
|
|
@ -1204,48 +1204,9 @@ private:
|
||||||
// We did inherit CSP in bug 1223647. If we do not already have a CSP, we
|
// We did inherit CSP in bug 1223647. If we do not already have a CSP, we
|
||||||
// should get it from the HTTP headers on the worker script.
|
// should get it from the HTTP headers on the worker script.
|
||||||
if (!mWorkerPrivate->GetCSP() && CSPService::sCSPEnabled) {
|
if (!mWorkerPrivate->GetCSP() && CSPService::sCSPEnabled) {
|
||||||
NS_ConvertASCIItoUTF16 cspHeaderValue(tCspHeaderValue);
|
rv = mWorkerPrivate->SetCSPFromHeaderValues(tCspHeaderValue,
|
||||||
NS_ConvertASCIItoUTF16 cspROHeaderValue(tCspROHeaderValue);
|
tCspROHeaderValue);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
nsIPrincipal* principal = mWorkerPrivate->GetPrincipal();
|
|
||||||
MOZ_ASSERT(principal, "Should not be null");
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
|
||||||
rv = principal->EnsureCSP(nullptr, getter_AddRefs(csp));
|
|
||||||
|
|
||||||
if (csp) {
|
|
||||||
// If there's a CSP header, apply it.
|
|
||||||
if (!cspHeaderValue.IsEmpty()) {
|
|
||||||
rv = CSP_AppendCSPFromHeader(csp, cspHeaderValue, false);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
}
|
|
||||||
// If there's a report-only CSP header, apply it.
|
|
||||||
if (!cspROHeaderValue.IsEmpty()) {
|
|
||||||
rv = CSP_AppendCSPFromHeader(csp, cspROHeaderValue, true);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set evalAllowed, default value is set in GetAllowsEval
|
|
||||||
bool evalAllowed = false;
|
|
||||||
bool reportEvalViolations = false;
|
|
||||||
rv = csp->GetAllowsEval(&reportEvalViolations, &evalAllowed);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
mWorkerPrivate->SetCSP(csp);
|
|
||||||
mWorkerPrivate->SetEvalAllowed(evalAllowed);
|
|
||||||
mWorkerPrivate->SetReportCSPViolations(reportEvalViolations);
|
|
||||||
|
|
||||||
// Set ReferrerPolicy, default value is set in GetReferrerPolicy
|
|
||||||
bool hasReferrerPolicy = false;
|
|
||||||
uint32_t rp = mozilla::net::RP_Default;
|
|
||||||
rv = csp->GetReferrerPolicy(&rp, &hasReferrerPolicy);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
|
|
||||||
if (hasReferrerPolicy) { //FIXME bug 1307366: move RP out of CSP code
|
|
||||||
mWorkerPrivate->SetReferrerPolicy(static_cast<net::ReferrerPolicy>(rp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (parent) {
|
if (parent) {
|
||||||
// XHR Params Allowed
|
// XHR Params Allowed
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
#include "mozilla/dom/MessageEventBinding.h"
|
#include "mozilla/dom/MessageEventBinding.h"
|
||||||
#include "mozilla/dom/MessagePort.h"
|
#include "mozilla/dom/MessagePort.h"
|
||||||
#include "mozilla/dom/MessagePortBinding.h"
|
#include "mozilla/dom/MessagePortBinding.h"
|
||||||
|
#include "mozilla/dom/nsCSPUtils.h"
|
||||||
#include "mozilla/dom/Performance.h"
|
#include "mozilla/dom/Performance.h"
|
||||||
#include "mozilla/dom/PMessagePort.h"
|
#include "mozilla/dom/PMessagePort.h"
|
||||||
#include "mozilla/dom/Promise.h"
|
#include "mozilla/dom/Promise.h"
|
||||||
|
|
@ -2382,6 +2383,56 @@ WorkerPrivateParent<Derived>::GetDocument() const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Derived>
|
||||||
|
nsresult
|
||||||
|
WorkerPrivateParent<Derived>::SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
|
||||||
|
const nsACString& aCSPReportOnlyHeaderValue)
|
||||||
|
{
|
||||||
|
AssertIsOnMainThread();
|
||||||
|
MOZ_DIAGNOSTIC_ASSERT(!mLoadInfo.mCSP);
|
||||||
|
|
||||||
|
NS_ConvertASCIItoUTF16 cspHeaderValue(aCSPHeaderValue);
|
||||||
|
NS_ConvertASCIItoUTF16 cspROHeaderValue(aCSPReportOnlyHeaderValue);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
||||||
|
nsresult rv = mLoadInfo.mPrincipal->EnsureCSP(nullptr, getter_AddRefs(csp));
|
||||||
|
if (!csp) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's a CSP header, apply it.
|
||||||
|
if (!cspHeaderValue.IsEmpty()) {
|
||||||
|
rv = CSP_AppendCSPFromHeader(csp, cspHeaderValue, false);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
// If there's a report-only CSP header, apply it.
|
||||||
|
if (!cspROHeaderValue.IsEmpty()) {
|
||||||
|
rv = CSP_AppendCSPFromHeader(csp, cspROHeaderValue, true);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set evalAllowed, default value is set in GetAllowsEval
|
||||||
|
bool evalAllowed = false;
|
||||||
|
bool reportEvalViolations = false;
|
||||||
|
rv = csp->GetAllowsEval(&reportEvalViolations, &evalAllowed);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// Set ReferrerPolicy, default value is set in GetReferrerPolicy
|
||||||
|
bool hasReferrerPolicy = false;
|
||||||
|
uint32_t rp = mozilla::net::RP_Unset;
|
||||||
|
rv = csp->GetReferrerPolicy(&rp, &hasReferrerPolicy);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
mLoadInfo.mCSP = csp;
|
||||||
|
mLoadInfo.mEvalAllowed = evalAllowed;
|
||||||
|
mLoadInfo.mReportCSPViolations = reportEvalViolations;
|
||||||
|
|
||||||
|
if (hasReferrerPolicy) {
|
||||||
|
mLoadInfo.mReferrerPolicy = static_cast<net::ReferrerPolicy>(rp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// Can't use NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerPrivateParent) because of the
|
// Can't use NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerPrivateParent) because of the
|
||||||
// templates.
|
// templates.
|
||||||
|
|
|
||||||
|
|
@ -701,6 +701,10 @@ public:
|
||||||
mLoadInfo.mCSP = aCSP;
|
mLoadInfo.mCSP = aCSP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
|
||||||
|
const nsACString& aCSPReportOnlyHeaderValue);
|
||||||
|
|
||||||
net::ReferrerPolicy
|
net::ReferrerPolicy
|
||||||
GetReferrerPolicy() const
|
GetReferrerPolicy() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue