Skip to content

Commit

Permalink
[SS-2024-002] Detect if debugging in HTML context (#11553)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Boyd <[email protected]>
  • Loading branch information
GuySartorelli and emteknetnz authored Jan 14, 2025
1 parent cd1d5de commit a555dad
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Dev/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,20 @@ protected static function supportsHTML(HTTPRequest $request = null)
if (Director::is_cli()) {
return false;
}
$accepted = [];

// Get current request if registered
if (!$request && Injector::inst()->has(HTTPRequest::class)) {
$request = Injector::inst()->get(HTTPRequest::class);
}
if (!$request) {
return false;
if ($request) {
$accepted = $request->getAcceptMimetypes(false);
} elseif (isset($_SERVER['HTTP_ACCEPT'])) {
// If there's no request object available, fallback to global $_SERVER
// This can happen in some circumstances when a PHP error is triggered
// during a regular HTTP request
$accepted = preg_split('#\s*,\s*#', $_SERVER['HTTP_ACCEPT']);
}
// Request must include text/html
$accepted = $request->getAcceptMimetypes(false);

// Explicit opt in
if (in_array('text/html', $accepted ?? [])) {
Expand Down

0 comments on commit a555dad

Please sign in to comment.