@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+60 -1
+53
resources/sql/autopatches/20170316.rawfiles.01.php
··· 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 + }
+7 -1
src/applications/differential/controller/DifferentialChangesetViewController.php
··· 350 350 $data = $changeset->makeOldFile(); 351 351 } 352 352 353 + $diff = $changeset->getDiff(); 354 + 353 355 $file = PhabricatorFile::newFromFileData( 354 356 $data, 355 357 array( 356 - 'name' => $changeset->getFilename(), 358 + 'name' => $changeset->getFilename(), 357 359 'mime-type' => 'text/plain', 360 + 'ttl' => phutil_units('24 hours in seconds'), 361 + 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 358 362 )); 363 + 364 + $file->attachToObject($diff->getPHID()); 359 365 360 366 $metadata[$key] = $file->getPHID(); 361 367 $changeset->setMetadata($metadata);