Commit f16fbe8a authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

Construct requested-with header at run time

There is evidence that malware is overwriting the memory of this header
string in the binary in order to avoid sending the header which then
identifies the app.

Try to confirm this theory by constructing the string from pieces at run
time which should disrupt a simple search / replace mechanism.

Bug: 1028189
Change-Id: I03b40a2a60ae29e06572d0bb501dba68acb4d201
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2416869Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808555}
parent 86bfd3ef
...@@ -351,11 +351,10 @@ void InterceptedRequest::InterceptResponseReceived( ...@@ -351,11 +351,10 @@ void InterceptedRequest::InterceptResponseReceived(
// compatibility with previous WebView versions. This should not be visible to // compatibility with previous WebView versions. This should not be visible to
// shouldInterceptRequest. It should also not trigger CORS prefetch if // shouldInterceptRequest. It should also not trigger CORS prefetch if
// OOR-CORS is enabled. // OOR-CORS is enabled.
if (!request_.headers.HasHeader( std::string header = content::GetCorsExemptRequestedWithHeaderName();
content::kCorsExemptRequestedWithHeaderName)) { if (!request_.headers.HasHeader(header)) {
request_.cors_exempt_headers.SetHeader( request_.cors_exempt_headers.SetHeader(
content::kCorsExemptRequestedWithHeaderName, header, base::android::BuildInfo::GetInstance()->host_package_name());
base::android::BuildInfo::GetInstance()->host_package_name());
} }
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
......
...@@ -2455,7 +2455,7 @@ void StoragePartitionImpl::InitNetworkContext() { ...@@ -2455,7 +2455,7 @@ void StoragePartitionImpl::InitNetworkContext() {
context_params->cors_exempt_header_list.push_back( context_params->cors_exempt_header_list.push_back(
kCorsExemptPurposeHeaderName); kCorsExemptPurposeHeaderName);
context_params->cors_exempt_header_list.push_back( context_params->cors_exempt_header_list.push_back(
kCorsExemptRequestedWithHeaderName); GetCorsExemptRequestedWithHeaderName());
variations::UpdateCorsExemptHeaderForVariations(context_params.get()); variations::UpdateCorsExemptHeaderForVariations(context_params.get());
cors_exempt_header_list_ = context_params->cors_exempt_header_list; cors_exempt_header_list_ = context_params->cors_exempt_header_list;
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "content/public/common/content_constants.h" #include "content/public/common/content_constants.h"
#include <vector>
#include "base/strings/string_util.h"
#include "build/branding_buildflags.h" #include "build/branding_buildflags.h"
namespace content { namespace content {
...@@ -44,7 +47,14 @@ const int kHistogramSynchronizerReservedSequenceNumber = 0; ...@@ -44,7 +47,14 @@ const int kHistogramSynchronizerReservedSequenceNumber = 0;
const int kDefaultDetachableCancelDelayMs = 30000; const int kDefaultDetachableCancelDelayMs = 30000;
const char kCorsExemptPurposeHeaderName[] = "Purpose"; const char kCorsExemptPurposeHeaderName[] = "Purpose";
const char kCorsExemptRequestedWithHeaderName[] = "X-Requested-With";
std::string GetCorsExemptRequestedWithHeaderName() {
std::vector<std::string> pieces;
pieces.push_back("X");
pieces.push_back("Requested");
pieces.push_back("With");
return base::JoinString(pieces, "-");
}
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_LINUX) || defined(OS_CHROMEOS)
const int kLowestRendererOomScore = 300; const int kLowestRendererOomScore = 300;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <stddef.h> // For size_t #include <stddef.h> // For size_t
#include <string>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
...@@ -63,7 +65,10 @@ CONTENT_EXPORT extern const int kDefaultDetachableCancelDelayMs; ...@@ -63,7 +65,10 @@ CONTENT_EXPORT extern const int kDefaultDetachableCancelDelayMs;
// in content need to know the name to manage the header stored in // in content need to know the name to manage the header stored in
// network::ResourceRequest::cors_exempt_headers. // network::ResourceRequest::cors_exempt_headers.
CONTENT_EXPORT extern const char kCorsExemptPurposeHeaderName[]; CONTENT_EXPORT extern const char kCorsExemptPurposeHeaderName[];
CONTENT_EXPORT extern const char kCorsExemptRequestedWithHeaderName[]; // This should just be a constant string, but there is evidence of malware
// overwriting the value of the constant so try to confirm by constructing
// it at run time.
CONTENT_EXPORT std::string GetCorsExemptRequestedWithHeaderName();
#if defined(OS_LINUX) || defined(OS_CHROMEOS) #if defined(OS_LINUX) || defined(OS_CHROMEOS)
// The OOM score adj constants // The OOM score adj constants
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment