Skip to content

Commit 156c709

Browse files
robertshieldCommit Bot
authored and
Commit Bot
committed
Disable environment variable override of API keys on official builds.
BUG=710575 Review-Url: https://codereview.chromium.org/2939403002 Cr-Commit-Position: refs/heads/master@{#480962}
1 parent 676e8cc commit 156c709

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

google_apis/google_api_keys.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ class APIKeyCache {
233233
// Gets a value for a key. In priority order, this will be the value
234234
// provided via a command-line switch, the value provided via an
235235
// environment variable, or finally a value baked into the build.
236-
// |command_line_switch| may be NULL.
236+
// |command_line_switch| may be NULL. Official Google Chrome builds will not
237+
// use the value provided by an environment variable.
237238
static std::string CalculateKeyValue(const char* baked_in_value,
238239
const char* environment_variable_name,
239240
const char* command_line_switch,
@@ -252,11 +253,17 @@ class APIKeyCache {
252253
<< " with value " << key_value << " from Info.plist.";
253254
}
254255
#endif
256+
257+
#if !defined(GOOGLE_CHROME_BUILD)
258+
// Don't allow using the environment to override API keys for official
259+
// Google Chrome builds. There have been reports of mangled environments
260+
// affecting users (crbug.com/710575).
255261
if (environment->GetVar(environment_variable_name, &temp)) {
256262
key_value = temp;
257263
VLOG(1) << "Overriding API key " << environment_variable_name
258264
<< " with value " << key_value << " from environment variable.";
259265
}
266+
#endif
260267

261268
if (command_line_switch && command_line->HasSwitch(command_line_switch)) {
262269
key_value = command_line->GetSwitchValueASCII(command_line_switch);

google_apis/google_api_keys_unittest.cc

+4
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ TEST_F(GoogleAPIKeysTest, OverrideAllKeys) {
394394
EXPECT_EQ("SECRET_REMOTING_HOST", secret_remoting_host);
395395
}
396396

397+
#if !defined(GOOGLE_CHROME_BUILD)
398+
397399
// Override all keys using both preprocessor defines and environment
398400
// variables. The environment variables should win.
399401
namespace override_all_keys_env {
@@ -481,6 +483,8 @@ TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) {
481483
EXPECT_EQ("env-SECRET_REMOTING_HOST", secret_remoting_host);
482484
}
483485

486+
#endif // !defined(GOOGLE_CHROME_BUILD)
487+
484488
#if defined(OS_IOS)
485489
// Override all keys using both preprocessor defines and setters.
486490
// Setters should win.

0 commit comments

Comments
 (0)