Skip to content

Commit afa69ee

Browse files
author
epriestley
committedJan 4, 2019
Remove an old digest in Celerity code and some obsolete configuration options
Summary: Ref T12509. This upgrades a `weakDigest()` callsite to SHA256-HMAC and removes three config options: - `celerity.resource-hash`: Now hard-coded, since the use case for ever adjusting it was very weak. - `celerity.enable-deflate`: Intended to make cache inspection easier, but we haven't needed to inspect caches in ~forever. - `celerity.minify`: Intended to make debugging minification easier, but we haven't needed to debug this in ~forever. In the latter two cases, the options were purely developer-focused, and it's easy to go add an `&& false` somewhere in the code if we need to disable these features to debug something, but the relevant parts of the code basically work properly and never need debugging. These options were excessively paranoid, based on the static resource enviroment at Facebook being far more perilous. The first case theoretically had end-user utility for fixing stuck content caches. In modern Phabricator, it's not intuitive that you'd go adjust a Config option to fix this. I don't recall any users ever actually running into problems here, though. (An earlier version of this change did more magic with `celerity.resource-hash`, but this ended up with a more substantial simplification.) Test Plan: Grepped for removed configuration options. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T12509 Differential Revision: https://secure.phabricator.com/D19941
1 parent 7e87d25 commit afa69ee

9 files changed

+1604
-1637
lines changed
 

‎conf/__init_conf__.php

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function phabricator_read_config_file($original_config) {
2121
return array(
2222
'phabricator.developer-mode' => true,
2323
'darkconsole.enabled' => true,
24-
'celerity.minify' => false,
2524
);
2625
}
2726

‎resources/celerity/map.php

+1,576-1,576
Large diffs are not rendered by default.

‎src/applications/cache/PhabricatorKeyValueDatabaseCache.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ private function willWriteValue($key, $value) {
145145

146146
static $can_deflate;
147147
if ($can_deflate === null) {
148-
$can_deflate = function_exists('gzdeflate') &&
149-
PhabricatorEnv::getEnvConfig('cache.enable-deflate');
148+
$can_deflate = function_exists('gzdeflate');
150149
}
151150

152151
if ($can_deflate) {

‎src/applications/celerity/CelerityResourceMapGenerator.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private function rebuildBinaryResources(
156156
$result_map = array();
157157

158158
foreach ($binary_map as $name => $data_hash) {
159-
$hash = $resources->getCelerityHash($data_hash.$name);
159+
$hash = $this->newResourceHash($data_hash.$name);
160160

161161
$result_map[$name] = array(
162162
'hash' => $hash,
@@ -185,8 +185,8 @@ private function rebuildTextResources(
185185
$raw_data = $resources->getResourceData($name);
186186
$xformed_data = $xformer->transformResource($name, $raw_data);
187187

188-
$data_hash = $resources->getCelerityHash($xformed_data);
189-
$hash = $resources->getCelerityHash($data_hash.$name);
188+
$data_hash = $this->newResourceHash($xformed_data);
189+
$hash = $this->newResourceHash($data_hash.$name);
190190

191191
list($provides, $requires) = $this->getProvidesAndRequires(
192192
$name,
@@ -324,7 +324,7 @@ private function rebuildPackages(
324324
$hashes[] = $symbol.':'.$symbol_hash;
325325
}
326326

327-
$hash = $resources->getCelerityHash(implode("\n", $hashes));
327+
$hash = $this->newResourceHash(implode("\n", $hashes));
328328
$package_map[$package_name] = array(
329329
'hash' => $hash,
330330
'symbols' => $package_symbols,
@@ -394,4 +394,14 @@ private function parseResourceSymbolList($list) {
394394
return $list;
395395
}
396396

397+
private function newResourceHash($data) {
398+
// This HMAC key is a static, hard-coded value because we don't want the
399+
// hashes in the map to depend on database state: when two different
400+
// developers regenerate the map, they should end up with the same output.
401+
402+
$hash = PhabricatorHash::digestHMACSHA256($data, 'celerity-resource-data');
403+
404+
return substr($hash, 0, 8);
405+
}
406+
397407
}

‎src/applications/celerity/controller/CelerityPhabricatorResourceController.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ public function handleRequest(AphrontRequest $request) {
3939
}
4040

4141
protected function buildResourceTransformer() {
42-
$minify_on = PhabricatorEnv::getEnvConfig('celerity.minify');
4342
$developer_on = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
44-
45-
$should_minify = ($minify_on && !$developer_on);
43+
$should_minify = !$developer_on;
4644

4745
return id(new CelerityResourceTransformer())
4846
->setMinify($should_minify)

‎src/applications/celerity/resources/CelerityResources.php

-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ public function getResourceModifiedTime($name) {
1212
return 0;
1313
}
1414

15-
public function getCelerityHash($data) {
16-
$tail = PhabricatorEnv::getEnvConfig('celerity.resource-hash');
17-
$hash = PhabricatorHash::weakDigest($data, $tail);
18-
return substr($hash, 0, 8);
19-
}
20-
2115
public function getResourceType($path) {
2216
return CelerityResourceTransformer::getResourceType($path);
2317
}

‎src/applications/config/check/PhabricatorExtraConfigSetupCheck.php

+8
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ public static function getAncientConfig() {
372372
'phpmailer.smtp-encoding' => $mailers_reason,
373373
'sendgrid.api-user' => $mailers_reason,
374374
'sendgrid.api-key' => $mailers_reason,
375+
376+
'celerity.resource-hash' => pht(
377+
'This option generally did not prove useful. Resource hash keys '.
378+
'are now managed automatically.'),
379+
'celerity.enable-deflate' => pht(
380+
'Resource deflation is now managed automatically.'),
381+
'celerity.minify' => pht(
382+
'Resource minification is now managed automatically.'),
375383
);
376384

377385
return $ancient_config;

‎src/applications/config/option/PhabricatorDeveloperConfigOptions.php

+4-30
Original file line numberDiff line numberDiff line change
@@ -146,38 +146,12 @@ public function getOptions() {
146146
pht('Enable developer mode'),
147147
pht('Disable developer mode'),
148148
))
149-
->setSummary(pht('Enable verbose error reporting and disk reads.'))
150-
->setDescription(
151-
pht(
152-
'This option enables verbose error reporting (stack traces, '.
153-
'error callouts) and forces disk reads of static assets on '.
154-
'every reload.')),
155-
$this->newOption('celerity.minify', 'bool', true)
156-
->setBoolOptions(
157-
array(
158-
pht('Minify static resources.'),
159-
pht("Don't minify static resources."),
160-
))
161-
->setSummary(pht('Minify static Celerity resources.'))
162-
->setDescription(
163-
pht(
164-
'Minify static resources by removing whitespace and comments. You '.
165-
'should enable this in production, but disable it in '.
166-
'development.')),
167-
$this->newOption('cache.enable-deflate', 'bool', true)
168-
->setBoolOptions(
169-
array(
170-
pht('Enable deflate compression'),
171-
pht('Disable deflate compression'),
172-
))
173-
->setSummary(
174-
pht('Toggle %s-based compression for some caches.', 'gzdeflate()'))
149+
->setSummary(pht('Enable verbose error reporting and disk reads.'))
175150
->setDescription(
176151
pht(
177-
'Set this to false to disable the use of %s-based '.
178-
'compression in some caches. This may give you less performant '.
179-
'(but more debuggable) caching.',
180-
'gzdeflate()')),
152+
'This option enables verbose error reporting (stack traces, '.
153+
'error callouts) and forces disk reads of static assets on '.
154+
'every reload.')),
181155
);
182156
}
183157
}

‎src/applications/config/option/PhabricatorSecurityConfigOptions.php

-15
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,6 @@ public function getOptions() {
234234
'Users can configure a URI pattern to open files in a text '.
235235
'editor. The URI must use a protocol on this whitelist.'))
236236
->setLocked(true),
237-
$this->newOption(
238-
'celerity.resource-hash',
239-
'string',
240-
'd9455ea150622ee044f7931dabfa52aa')
241-
->setSummary(
242-
pht('An input to the hash function when building resource hashes.'))
243-
->setDescription(
244-
pht(
245-
'This value is an input to the hash function when building '.
246-
'resource hashes. It has no security value, but if you '.
247-
'accidentally poison user caches (by pushing a bad patch or '.
248-
'having something go wrong with a CDN, e.g.) you can change this '.
249-
'to something else and rebuild the Celerity map to break user '.
250-
'caches. Unless you are doing Celerity development, it is '.
251-
'exceptionally unlikely that you need to modify this.')),
252237
$this->newOption('remarkup.enable-embedded-youtube', 'bool', false)
253238
->setBoolOptions(
254239
array(

0 commit comments

Comments
 (0)
Failed to load comments.