Issue #2542 - Part 6: Add Sec-Fetch-User header for all requests that are the direct result of a system principal request.

This means navigation resulting from interaction with the browser UI
should result in a -user header (address bar navigation, bookmarks, etc.)
This commit is contained in:
Moonchild 2024-07-04 22:40:06 +02:00 committed by roytam1
commit 53149ed646

View file

@ -271,12 +271,22 @@ void SecFetch::AddSecFetchSite(nsIHttpChannel* aHTTPChannel) {
}
void SecFetch::AddSecFetchUser(nsIHttpChannel* aHTTPChannel) {
// TODO: Bug 1621987: Implement Sec-Fetch-User
bool userInitiated = false;
nsCOMPtr<nsILoadInfo> loadInfo = aHTTPChannel->GetLoadInfo();
// A request issued by the browser is always assumed user-initiated.
if (nsContentUtils::IsSystemPrincipal(loadInfo->TriggeringPrincipal())) {
userInitiated = true;
}
// nsAutoCString user("?1");
// nsresult rv = aHTTPChannel->SetRequestHeader(
// NS_LITERAL_CSTRING("Sec-Fetch-User"), user, false);
// Unused << NS_WARN_IF(NS_FAILED(rv));
// TODO: Implement content interaction
nsAutoCString user("?1");
if (userInitiated) {
nsresult rv = aHTTPChannel->SetRequestHeader(NS_LITERAL_CSTRING("Sec-Fetch-User"), user, false);
Unused << NS_WARN_IF(NS_FAILED(rv));
}
}
void SecFetch::AddSecFetchHeader(nsIHttpChannel* aHTTPChannel) {