ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\FileDelivery\Delivery\BaseDelivery Class Reference
+ Inheritance diagram for ILIAS\FileDelivery\Delivery\BaseDelivery:
+ Collaboration diagram for ILIAS\FileDelivery\Delivery\BaseDelivery:

Public Member Functions

 __construct (protected GlobalHttpState $http, protected ResponseBuilder $response_builder, protected ResponseBuilder $fallback_response_builder, protected IsolationConfig $isolation=new IsolationConfig(false, null, null),)
 

Protected Member Functions

 isRequestHostAllowed ()
 When user content isolation is active, only requests targeting the configured content domain may be served. More...
 
 isRequestOnContentHost ()
 Inverse of {. More...
 
 notFound (ResponseInterface $r)
 Send an empty 404 response and terminate. More...
 
 saveAndClose (ResponseInterface $r, ?string $path_to_delete=null)
 
 setGeneralHeaders (ResponseInterface $r, string $uri, string $mime_type, string $file_name, Disposition $disposition=Disposition::INLINE, bool $isolated=true)
 
 applyIsolationHeaders (ResponseInterface $r)
 When isolation is active, harden delivery responses: More...
 

Protected Attributes

const MIME_TYPE_MAP = __DIR__ . '/../../../FileUpload/src/mime_type_map.php'
 
array $mime_type_map
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 32 of file BaseDelivery.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\FileDelivery\Delivery\BaseDelivery::__construct ( protected GlobalHttpState  $http,
protected ResponseBuilder  $response_builder,
protected ResponseBuilder  $fallback_response_builder,
protected IsolationConfig  $isolation = new IsolationConfig(false, null, null) 
)

Definition at line 38 of file BaseDelivery.php.

43 {
44 if (is_readable(self::MIME_TYPE_MAP)) {
45 $map = include self::MIME_TYPE_MAP;
46 }
47 $this->mime_type_map = $map ?? [];
48 }

References ILIAS\FileDelivery\Delivery\BaseDelivery\MIME_TYPE_MAP.

Member Function Documentation

◆ applyIsolationHeaders()

ILIAS\FileDelivery\Delivery\BaseDelivery::applyIsolationHeaders ( ResponseInterface  $r)
protected

When isolation is active, harden delivery responses:

  • prevent MIME sniffing
  • mark as cross-origin so the main app may embed assets via , <iframe>, …
  • allow CORS access only from the configured ILIAS domain
  • strip referrer to avoid leaking the content domain back to the app

Definition at line 153 of file BaseDelivery.php.

153 : ResponseInterface
154 {
155 if (!$this->isolation->isActivated()) {
156 return $r;
157 }
158
159 $r = $r->withHeader(ResponseHeader::X_CONTENT_TYPE_OPTIONS, 'nosniff');
160 $r = $r->withHeader('Cross-Origin-Resource-Policy', 'cross-origin');
161 $r = $r->withHeader('Referrer-Policy', 'no-referrer');
162
163 if (($ilias_domain = $this->isolation->getIliasDomain()) !== null) {
164 $r = $r->withHeader(ResponseHeader::ACCESS_CONTROL_ALLOW_ORIGIN, $ilias_domain);
165 $r = $r->withAddedHeader('Vary', 'Origin');
166 }
167
168 return $r;
169 }

◆ isRequestHostAllowed()

ILIAS\FileDelivery\Delivery\BaseDelivery::isRequestHostAllowed ( )
protected

When user content isolation is active, only requests targeting the configured content domain may be served.

Requests reaching the delivery endpoint via the main ILIAS domain are rejected.

Definition at line 55 of file BaseDelivery.php.

55 : bool
56 {
57 if (!$this->isolation->isActivated()) {
58 return true;
59 }
60
61 $expected = $this->isolation->getContentHost();
62 if ($expected === null) {
63 return true;
64 }
65
66 return strcasecmp($this->http->request()->getUri()->getHost(), $expected) === 0;
67 }
static http()
Fetches the global http state from ILIAS.

References ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ isRequestOnContentHost()

ILIAS\FileDelivery\Delivery\BaseDelivery::isRequestOnContentHost ( )
protected

Inverse of {.

See also
self::isRequestHostAllowed()} for the legacy/internal delivery path: the content domain is reserved for signed token delivery via deliver.php. Legacy or app-context delivery must never happen on the content host, so callers reject such requests.

Definition at line 75 of file BaseDelivery.php.

75 : bool
76 {
77 if (!$this->isolation->isActivated()) {
78 return false;
79 }
80
81 $content_host = $this->isolation->getContentHost();
82 if ($content_host === null) {
83 return false;
84 }
85
86 return strcasecmp($this->http->request()->getUri()->getHost(), $content_host) === 0;
87 }

References ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ notFound()

ILIAS\FileDelivery\Delivery\BaseDelivery::notFound ( ResponseInterface  $r)
protected

Send an empty 404 response and terminate.

Declared never so the type system guarantees callers cannot fall through to actually serving a file after a rejected request.

Definition at line 94 of file BaseDelivery.php.

94 : never
95 {
96 $this->http->saveResponse($r->withStatus(404));
97 $this->http->sendResponse();
98 $this->http->close();
99 }

References ILIAS\FileDelivery\http().

+ Here is the call graph for this function:

◆ saveAndClose()

ILIAS\FileDelivery\Delivery\BaseDelivery::saveAndClose ( ResponseInterface  $r,
?string  $path_to_delete = null 
)
protected

Definition at line 101 of file BaseDelivery.php.

104 : never {
105 if ($path_to_delete !== null && file_exists($path_to_delete)) {
106 // close() ends the request, the file can only be deleted by a shutdown function,
107 // see https://mantis.ilias.de/view.php?id=48312
108 ignore_user_abort(true);
109 set_time_limit(0);
110 register_shutdown_function(static function () use ($path_to_delete): void {
111 if (file_exists($path_to_delete)) {
112 unlink($path_to_delete);
113 }
114 });
115 }
116
117 $this->http->saveResponse($r);
118 $this->http->sendResponse();
119 $this->http->close();
120 }

◆ setGeneralHeaders()

ILIAS\FileDelivery\Delivery\BaseDelivery::setGeneralHeaders ( ResponseInterface  $r,
string  $uri,
string  $mime_type,
string  $file_name,
Disposition  $disposition = Disposition::INLINE,
bool  $isolated = true 
)
protected

Definition at line 122 of file BaseDelivery.php.

129 : ResponseInterface {
130 $r = $r->withHeader('X-ILIAS-FileDelivery-Method', $this->response_builder->getName());
131 $r = $r->withHeader(ResponseHeader::CONTENT_TYPE, $mime_type);
132 $r = $r->withHeader(
134 (new ContentDispositionHeader())->build($disposition->value, $file_name)
135 );
136 $r = $r->withHeader(ResponseHeader::CACHE_CONTROL, 'max-age=31536000, immutable, private');
137 $r = $r->withHeader(
139 date("D, j M Y H:i:s", strtotime('+5 days')) . " GMT"
140 );
141
142 // files delivered on the ILIAS domain are same-origin, the cross-origin headers do not apply
143 return $isolated ? $this->applyIsolationHeaders($r) : $r;
144 }
applyIsolationHeaders(ResponseInterface $r)
When isolation is active, harden delivery responses:

Field Documentation

◆ $mime_type_map

array ILIAS\FileDelivery\Delivery\BaseDelivery::$mime_type_map
protected

Definition at line 36 of file BaseDelivery.php.

◆ MIME_TYPE_MAP

const ILIAS\FileDelivery\Delivery\BaseDelivery::MIME_TYPE_MAP = __DIR__ . '/../../../FileUpload/src/mime_type_map.php'
protected

The documentation for this class was generated from the following file: