fix(roles): degrade instead of 500 when the roles header is absent - #1605
Open
azuretek wants to merge 1 commit into
Open
fix(roles): degrade instead of 500 when the roles header is absent#1605azuretek wants to merge 1 commit into
azuretek wants to merge 1 commit into
Conversation
The view composer reads $_SERVER[AUTH_ROLES_HTTP_HEADER] unguarded, so any request that reaches Heimdall without passing through the reverse proxy returns a 500 rather than a dashboard. That covers a container healthcheck, a probe on the published port, and the window before the proxy is configured. Every view goes through this composer, so no page renders at all: ErrorException: Undefined array key "HTTP_X_TOKEN_USER_ROLES" at app/Providers/AppServiceProvider.php:95 Coalesce the missing header to an empty string, which fails closed on the admin check that follows. Do the same in ItemController::dash(), where the header is passed straight to explode() and null has been deprecated as a string argument since PHP 8.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1604.
Problem
In roles mode
AppServiceProviderreads$_SERVER[config('app.auth_roles_http_header')]with no guard, inside aview()->composer('*')callback. Any request that arrives without the roles header returns HTTP 500, and because the composer is registered against every view, no page renders at all. A container healthcheck, a probe on the published port, or a request made before the proxy is configured each produce:Change
Coalesce the header to an empty string before splitting it. That fails closed on the
in_arrayimmediately below: an absent header is no roles, never the admin role.ItemController::dash()reads the same header through the request object, which returnsnullinstead of throwing, so it does not fatal, but it then passesnulltoexplode(), deprecated as a string argument since PHP 8.1. Same coalesce there.The long line is wrapped as a side effect, which drops one file from the phpcs report.
Test
tests/Feature/RolesHeaderMissingTest.php, 4 cases: the page renders, it fails closed on admin controls, it shows no tiles, and the admin role still works when the header is present.On
2.xwithout the change, 3 of the 4 fail with the production error, and the case that supplies the header passes:With the change, all 4 pass.
Suite and linter,
php artisan testand./vendor/bin/phpcs --report=summary:2.xThe 4 added tests are the whole test difference. The phpcs count is unchanged; the file count drops by one because the wrapped line no longer exceeds 120 characters.
Live verification
Built as an overlay on the stock
linuxserver/heimdallimage we run and A/B'd against a copy of our live config:GET /with no roles headerGET /as the admin role