Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/private/AppFramework/Http/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ public function setReadfile($path) {
*/
#[\Override]
public function setHeader($header) {
// Apache mod_proxy_fcgi parses FCGI response headers with a buffer
// hardcoded at HUGE_STRING_LEN (8192 bytes in httpd.h); 7800 leaves
// a safety margin for the status line and surrounding header bytes.
$maxLen = 7800;
Comment thread
n-iv marked this conversation as resolved.
if (strlen($header) > $maxLen) {
foreach (['Content-Security-Policy:', 'Feature-Policy:'] as $prefix) {
if (str_starts_with($header, $prefix)) {
$value = ltrim(substr($header, strlen($prefix)));
$directives = array_filter(array_map(trim(...), explode(';', $value)));
$segment = '';
$first = true;
foreach ($directives as $directive) {
$candidate = $segment === '' ? $directive : $segment . ';' . $directive;
if (strlen($prefix . ' ' . $candidate . ';') > $maxLen && $segment !== '') {
header($prefix . ' ' . $segment . ';', $first);
$first = false;
$segment = $directive;
} else {
$segment = $candidate;
}
}
if ($segment !== '') {
header($prefix . ' ' . $segment . ';', $first);
}
Comment thread
n-iv marked this conversation as resolved.
return;
}
}
}
header($header);
}

Expand Down