mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 16:58:38 +09:00
Issue #2648 - Apply CSP to documents sent through multipart/x-mixed-replace
This commit is contained in:
parent
8d536c0cc7
commit
6fe326c7bb
2 changed files with 32 additions and 1 deletions
|
|
@ -644,6 +644,7 @@ nsMultiMixedConv::OnDataAvailable(nsIRequest *request, nsISupports *context,
|
|||
mContentType.Truncate();
|
||||
mContentLength = UINT64_MAX;
|
||||
mContentDisposition.Truncate();
|
||||
mContentSecurityPolicy.Truncate();
|
||||
mIsByteRangeRequest = false;
|
||||
mByteRangeStart = 0;
|
||||
mByteRangeEnd = 0;
|
||||
|
|
@ -715,6 +716,12 @@ nsMultiMixedConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) {
|
|||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
nsCString csp;
|
||||
rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-security-policy"),
|
||||
csp);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mRootContentSecurityPolicy = csp;
|
||||
}
|
||||
} else {
|
||||
// try asking the channel directly
|
||||
rv = channel->GetContentType(delimiter);
|
||||
|
|
@ -1062,6 +1069,28 @@ nsMultiMixedConv::ParseHeaders(nsIChannel *aChannel, char *&aPtr,
|
|||
mIsByteRangeRequest = true;
|
||||
if (mContentLength == UINT64_MAX)
|
||||
mContentLength = uint64_t(mByteRangeEnd - mByteRangeStart + 1);
|
||||
} else if (headerStr.LowerCaseEqualsLiteral("content-security-policy")) {
|
||||
mContentSecurityPolicy = headerVal;
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
|
||||
if (httpChannel) {
|
||||
nsCString resultCSP = mRootContentSecurityPolicy;
|
||||
if (!mContentSecurityPolicy.IsEmpty()) {
|
||||
// We are updating the root channel CSP header respectively for
|
||||
// each part as: CSP-root + CSP-partN, where N is the part number.
|
||||
// Here we append current part's CSP to root CSP and reset CSP
|
||||
// header for each part.
|
||||
if (!resultCSP.IsEmpty()) {
|
||||
resultCSP.Append(";");
|
||||
}
|
||||
resultCSP.Append(mContentSecurityPolicy);
|
||||
}
|
||||
nsresult rv = httpChannel->SetResponseHeader(
|
||||
NS_LITERAL_CSTRING("Content-Security-Policy"),
|
||||
resultCSP, false);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_CORRUPTED_CONTENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*newLine = tmpChar;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue