Skip to content

Commit 6f87955

Browse files
author
epriestley
committed
(stable) Correct an issue where "View Raw File" in Differential generated a file with overbroad permissions
Summary: Via HackerOne. When you view a raw file in Differential, we currently generate a permanent file with default permissions. This may be incorrect: default permissions may be broader than the diff's permissions. The other three methods of downloading/viewing raw files ("Download" in Diffusion and Differential, "View Raw" in Diffusion and Differential) already apply policies correctly and generate temporary files. However, this workflow was missed when other workflows were updated. Beyond updating the workflow, delete any files we've generated in the past. This wipes the slate clean on any security issues and frees up a little disk space. Test Plan: - Ran migration script, saw existing files get purged. - Did "View Raw File", got a new file. - Verified that the file was temporary and properly attached to the diff, with "NO ONE" permissions. - Double-checked that Diffusion already runs policy logic correctly and applies appropriate policies. - Double-checked that "Download Raw Diff" in Differential already runs policy logic correctly. - Double-chekced that "Download Raw Diff" in Diffusion already runs policy logic correctly. Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D17504
1 parent ae5f797 commit 6f87955

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
// Previously, files generated by "View Raw File" were written as permanent
4+
// files with excessively wide view permissions. This destroys these files
5+
// so they are recreated as temporary files with correct permissions when
6+
// next accessed.
7+
8+
$table = new DifferentialChangeset();
9+
$conn = $table->establishConnection('w');
10+
$viewer = PhabricatorUser::getOmnipotentUser();
11+
12+
$iterator = new LiskRawMigrationIterator(
13+
$conn,
14+
$table->getTableName());
15+
16+
echo tsprintf(
17+
"%s\n",
18+
pht('Purging old raw changeset file caches...'));
19+
20+
$keys = array(
21+
'raw:new:phid',
22+
'raw:old:phid',
23+
);
24+
25+
foreach ($iterator as $changeset) {
26+
try {
27+
$metadata = phutil_json_decode($changeset['metadata']);
28+
29+
$phids = array();
30+
foreach ($keys as $key) {
31+
if (isset($metadata[$key])) {
32+
$phids[] = $metadata[$key];
33+
}
34+
}
35+
36+
foreach ($phids as $phid) {
37+
$file = id(new PhabricatorFileQuery())
38+
->setViewer($viewer)
39+
->withPHIDs(array($phid))
40+
->executeOne();
41+
if ($file) {
42+
id(new PhabricatorDestructionEngine())
43+
->destroyObject($file);
44+
}
45+
}
46+
47+
// NOTE: We don't bother updating the changeset record itself: we already
48+
// regenerate the cache properly if the stored value isn't valid.
49+
50+
} catch (Exception $ex) {
51+
// Just move on if we run into trouble.
52+
}
53+
}

src/applications/differential/controller/DifferentialChangesetViewController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,19 @@ private function buildRawFileResponse(
350350
$data = $changeset->makeOldFile();
351351
}
352352

353+
$diff = $changeset->getDiff();
354+
353355
$file = PhabricatorFile::newFromFileData(
354356
$data,
355357
array(
356-
'name' => $changeset->getFilename(),
358+
'name' => $changeset->getFilename(),
357359
'mime-type' => 'text/plain',
360+
'ttl' => phutil_units('24 hours in seconds'),
361+
'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
358362
));
359363

364+
$file->attachToObject($diff->getPHID());
365+
360366
$metadata[$key] = $file->getPHID();
361367
$changeset->setMetadata($metadata);
362368
$changeset->save();

0 commit comments

Comments
 (0)