phid = $data['phid']; $this->key = $data['key']; } public function shouldRequireLogin() { return false; } public function processRequest() { $alt = PhabricatorEnv::getEnvConfig('security.alternate-file-domain'); if (!$alt) { return new Aphront400Response(); } $request = $this->getRequest(); $alt_domain = id(new PhutilURI($alt))->getDomain(); if ($alt_domain != $request->getHost()) { return new Aphront400Response(); } $file = id(new PhabricatorFile())->loadOneWhere( 'phid = %s', $this->phid); if (!$file) { return new Aphront404Response(); } if (!$file->validateSecretKey($this->key)) { return new Aphront404Response(); } // It's safe to bypass view restrictions because we know we are being served // off an alternate domain which we will not set cookies on. $data = $file->loadFileData(); $response = new AphrontFileResponse(); $response->setContent($data); $response->setMimeType($file->getMimeType()); $response->setCacheDurationInSeconds(60 * 60 * 24 * 30); return $response; } }