Repository navigation
M19.2: Auth hardening — graceful 419/session-expiry → login with return-to-page #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a1ba423
Sail: gate scheduler + queue workers on healthy MySQL
n8bar 4b00a96
19.4: cross-reference #96 (branded custom error pages) as candidate s…
n8bar eb2c2ae
19.2 §1+§2: lock return-to-page, capture survey, spec belt-and-suspen…
n8bar b5f049b
19.2 §2+§3: 419/session-expiry → login with return-to-page
n8bar 81c6fcd
19.2 §3: close GET-idle banner as default-by-design; §3 done
n8bar 45ab9df
19.2 §3.2: banner GET-idle expiry via cz_returning marker cookie
n8bar a5aab05
M19.2 close-out: Phase 2 complete; x-prefix strategy doc
n8bar 113e69c
M19.2 close-out: mark Phase 2 done (content for the x-prefix rename)
n8bar 528e979
19.3: restructure to parent-first (CyberCreek → CryptoZing)
n8bar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| namespace App\Support; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Routing\Exceptions\UrlGenerationException; | ||
| use Illuminate\Support\Facades\Route; | ||
| use Symfony\Component\HttpKernel\Exception\HttpException; | ||
|
|
||
| /** | ||
| * Resolves the page a user should be returned to after re-authenticating | ||
| * following a 419 / session-expiry bounce. | ||
| * | ||
| * The candidate is read from a hidden `_return_to` field first (it rides in | ||
| * the POST body, so it survives even when the session and CSRF token are | ||
| * gone), then falls back to the Referer header. A candidate is only accepted | ||
| * when it points at a same-origin GET route — never the POST/PATCH/DELETE | ||
| * action that just failed, so the mutation is never implicitly replayed. | ||
| * Anything that fails validation returns null, and callers fall back to the | ||
| * dashboard. | ||
| */ | ||
| class ReturnToResolver | ||
| { | ||
| public static function resolve(Request $request): ?string | ||
| { | ||
| $candidate = $request->input('_return_to'); | ||
|
|
||
| if (! is_string($candidate) || trim($candidate) === '') { | ||
| $candidate = $request->headers->get('referer'); | ||
| } | ||
|
|
||
| if (! is_string($candidate) || trim($candidate) === '') { | ||
| return null; | ||
| } | ||
|
|
||
| $candidate = trim($candidate); | ||
|
|
||
| if (! self::isSameOrigin($request, $candidate)) { | ||
| return null; | ||
| } | ||
|
|
||
| if (! self::resolvesToGetRoute($candidate)) { | ||
| return null; | ||
| } | ||
|
|
||
| return $candidate; | ||
| } | ||
|
|
||
| private static function isSameOrigin(Request $request, string $candidate): bool | ||
| { | ||
| $parts = parse_url($candidate); | ||
|
|
||
| if ($parts === false || ! isset($parts['host'])) { | ||
| return false; | ||
| } | ||
|
|
||
| if (($parts['scheme'] ?? $request->getScheme()) !== $request->getScheme()) { | ||
| return false; | ||
| } | ||
|
|
||
| return strcasecmp($parts['host'], $request->getHost()) === 0; | ||
| } | ||
|
|
||
| private static function resolvesToGetRoute(string $candidate): bool | ||
| { | ||
| $path = parse_url($candidate, PHP_URL_PATH) ?: '/'; | ||
|
|
||
| $probe = Request::create($path, 'GET'); | ||
|
|
||
| try { | ||
| $route = Route::getRoutes()->match($probe); | ||
| } catch (HttpException | UrlGenerationException) { | ||
| return false; | ||
| } | ||
|
|
||
| return in_array('GET', $route->methods(), true); | ||
| } | ||
| } |
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
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
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
DB_PASSWORDis anything other than the literalpassword—including the checked-in.env.example, where it is empty—this new wait loop never exits even afterdepends_on: condition: service_healthypasses, so the scheduler stays stuck instead of starting; the queue worker has the same hard-coded-ppasswordon line 55. The mysqladmin docs define-p[password]as the password value sent to the server, so this needs to use the Compose-provided DB password (or skip-password for the empty-password case) rather than a fixed value.Useful? React with 👍 / 👎.