mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-22 15:17:29 +09:00
Issue #2402 - CSP violation: blockedURI inline/eval. https://bugzilla.mozilla.org/show_bug.cgi?id=1418241 CSP: Blocked URI should be empty for inline violations. https://bugzilla.mozilla.org/show_bug.cgi?id=1236222
This commit is contained in:
parent
811bcbefd4
commit
9cd8aafeaa
2 changed files with 30 additions and 32 deletions
|
|
@ -489,7 +489,7 @@ nsCSPContext::reportInlineViolation(nsContentPolicyType aContentType,
|
||||||
|
|
||||||
nsCOMPtr<nsISupportsCString> selfICString(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
|
nsCOMPtr<nsISupportsCString> selfICString(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
|
||||||
if (selfICString) {
|
if (selfICString) {
|
||||||
selfICString->SetData(nsDependentCString("self"));
|
selfICString->SetData(nsDependentCString("inline"));
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsISupports> selfISupports(do_QueryInterface(selfICString));
|
nsCOMPtr<nsISupports> selfISupports(do_QueryInterface(selfICString));
|
||||||
|
|
||||||
|
|
@ -652,7 +652,16 @@ nsCSPContext::LogViolationDetails(uint16_t aViolationType,
|
||||||
|
|
||||||
nsCOMPtr<nsISupportsCString> selfICString(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
|
nsCOMPtr<nsISupportsCString> selfICString(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
|
||||||
if (selfICString) {
|
if (selfICString) {
|
||||||
selfICString->SetData(nsDependentCString("self"));
|
if (aViolationType == nsIContentSecurityPolicy::VIOLATION_TYPE_EVAL) {
|
||||||
|
selfICString->SetData(nsDependentCString("eval"));
|
||||||
|
} else if (aViolationType == nsIContentSecurityPolicy::VIOLATION_TYPE_INLINE_SCRIPT ||
|
||||||
|
aViolationType == nsIContentSecurityPolicy::VIOLATION_TYPE_INLINE_STYLE) {
|
||||||
|
selfICString->SetData(nsDependentCString("inline"));
|
||||||
|
} else {
|
||||||
|
// All the other types should have a URL, but just in case, let's use
|
||||||
|
// 'self' here.
|
||||||
|
selfICString->SetData(nsDependentCString("self"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsISupports> selfISupports(do_QueryInterface(selfICString));
|
nsCOMPtr<nsISupports> selfISupports(do_QueryInterface(selfICString));
|
||||||
|
|
||||||
|
|
@ -827,7 +836,8 @@ StripURIForReporting(nsIURI* aURI,
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsCSPContext::GatherSecurityPolicyViolationEventData(
|
nsCSPContext::GatherSecurityPolicyViolationEventData(
|
||||||
nsISupports* aBlockedContentSource,
|
nsIURI* aBlockedURI,
|
||||||
|
const nsACString& aBlockedString,
|
||||||
nsIURI* aOriginalURI,
|
nsIURI* aOriginalURI,
|
||||||
nsAString& aViolatedDirective,
|
nsAString& aViolatedDirective,
|
||||||
uint32_t aViolatedPolicyIndex,
|
uint32_t aViolatedPolicyIndex,
|
||||||
|
|
@ -861,24 +871,12 @@ nsCSPContext::GatherSecurityPolicyViolationEventData(
|
||||||
aViolationEventInit.mReferrer = mReferrer;
|
aViolationEventInit.mReferrer = mReferrer;
|
||||||
|
|
||||||
// blocked-uri
|
// blocked-uri
|
||||||
if (aBlockedContentSource) {
|
if (aBlockedURI) {
|
||||||
nsAutoCString reportBlockedURI;
|
nsAutoCString reportBlockedURI;
|
||||||
nsCOMPtr<nsIURI> uri = do_QueryInterface(aBlockedContentSource);
|
StripURIForReporting(aBlockedURI, mSelfURI, reportBlockedURI);
|
||||||
// could be a string or URI
|
|
||||||
if (uri) {
|
|
||||||
StripURIForReporting(uri, mSelfURI, reportBlockedURI);
|
|
||||||
} else {
|
|
||||||
nsCOMPtr<nsISupportsCString> cstr = do_QueryInterface(aBlockedContentSource);
|
|
||||||
if (cstr) {
|
|
||||||
cstr->GetData(reportBlockedURI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (reportBlockedURI.IsEmpty()) {
|
|
||||||
// this can happen for frame-ancestors violation where the violating
|
|
||||||
// ancestor is cross-origin.
|
|
||||||
NS_WARNING("No blocked URI (null aBlockedContentSource) for CSP violation report.");
|
|
||||||
}
|
|
||||||
aViolationEventInit.mBlockedURI = NS_ConvertUTF8toUTF16(reportBlockedURI);
|
aViolationEventInit.mBlockedURI = NS_ConvertUTF8toUTF16(reportBlockedURI);
|
||||||
|
} else {
|
||||||
|
aViolationEventInit.mBlockedURI = NS_ConvertUTF8toUTF16(aBlockedString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// effective-directive
|
// effective-directive
|
||||||
|
|
@ -1198,8 +1196,16 @@ class CSPReportSenderRunnable final : public Runnable
|
||||||
|
|
||||||
// 0) prepare violation data
|
// 0) prepare violation data
|
||||||
mozilla::dom::SecurityPolicyViolationEventInit init;
|
mozilla::dom::SecurityPolicyViolationEventInit init;
|
||||||
|
// mBlockedContentSource could be a URI or a string.
|
||||||
|
nsCOMPtr<nsIURI> blockedURI = do_QueryInterface(mBlockedContentSource);
|
||||||
|
// if mBlockedContentSource is not a URI, it could be a string
|
||||||
|
nsCOMPtr<nsISupportsCString> blockedICString = do_QueryInterface(mBlockedContentSource);
|
||||||
|
nsAutoCString blockedDataStr;
|
||||||
|
if (blockedICString) {
|
||||||
|
blockedICString->GetData(blockedDataStr);
|
||||||
|
}
|
||||||
rv = mCSPContext->GatherSecurityPolicyViolationEventData(
|
rv = mCSPContext->GatherSecurityPolicyViolationEventData(
|
||||||
mBlockedContentSource, mOriginalURI,
|
blockedURI, blockedDataStr, mOriginalURI,
|
||||||
mViolatedDirective, mViolatedPolicyIndex,
|
mViolatedDirective, mViolatedPolicyIndex,
|
||||||
mSourceFile, mScriptSample, mLineNum,
|
mSourceFile, mScriptSample, mLineNum,
|
||||||
init);
|
init);
|
||||||
|
|
@ -1217,12 +1223,6 @@ class CSPReportSenderRunnable final : public Runnable
|
||||||
mCSPContext->SendReports(init, mViolatedPolicyIndex);
|
mCSPContext->SendReports(init, mViolatedPolicyIndex);
|
||||||
|
|
||||||
// 3) log to console (one per policy violation)
|
// 3) log to console (one per policy violation)
|
||||||
// mBlockedContentSource could be a URI or a string.
|
|
||||||
nsCOMPtr<nsIURI> blockedURI = do_QueryInterface(mBlockedContentSource);
|
|
||||||
// if mBlockedContentSource is not a URI, it could be a string
|
|
||||||
nsCOMPtr<nsISupportsCString> blockedString = do_QueryInterface(mBlockedContentSource);
|
|
||||||
|
|
||||||
nsCString blockedDataStr;
|
|
||||||
|
|
||||||
if (blockedURI) {
|
if (blockedURI) {
|
||||||
blockedURI->GetSpec(blockedDataStr);
|
blockedURI->GetSpec(blockedDataStr);
|
||||||
|
|
@ -1232,8 +1232,6 @@ class CSPReportSenderRunnable final : public Runnable
|
||||||
blockedDataStr.Truncate(40);
|
blockedDataStr.Truncate(40);
|
||||||
blockedDataStr.AppendASCII("...");
|
blockedDataStr.AppendASCII("...");
|
||||||
}
|
}
|
||||||
} else if (blockedString) {
|
|
||||||
blockedString->GetData(blockedDataStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockedDataStr.Length() > 0) {
|
if (blockedDataStr.Length() > 0) {
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,8 @@ class nsCSPContext : public nsIContentSecurityPolicy
|
||||||
/**
|
/**
|
||||||
* Construct SecurityPolicyViolationEventInit structure.
|
* Construct SecurityPolicyViolationEventInit structure.
|
||||||
*
|
*
|
||||||
* @param aBlockedContentSource
|
* @param aBlockedURI
|
||||||
* Either a CSP Source (like 'self', as string) or nsIURI: the source
|
* A nsIURI: the source of the violation.
|
||||||
* of the violation.
|
|
||||||
* @param aOriginalUri
|
* @param aOriginalUri
|
||||||
* The original URI if the blocked content is a redirect, else null
|
* The original URI if the blocked content is a redirect, else null
|
||||||
* @param aViolatedDirective
|
* @param aViolatedDirective
|
||||||
|
|
@ -78,7 +77,8 @@ class nsCSPContext : public nsIContentSecurityPolicy
|
||||||
* The output
|
* The output
|
||||||
*/
|
*/
|
||||||
nsresult GatherSecurityPolicyViolationEventData(
|
nsresult GatherSecurityPolicyViolationEventData(
|
||||||
nsISupports* aBlockedContentSource,
|
nsIURI* aBlockedURI,
|
||||||
|
const nsACString& aBlockedString,
|
||||||
nsIURI* aOriginalURI,
|
nsIURI* aOriginalURI,
|
||||||
nsAString& aViolatedDirective,
|
nsAString& aViolatedDirective,
|
||||||
uint32_t aViolatedPolicyIndex,
|
uint32_t aViolatedPolicyIndex,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue