Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

Addresses security vulnerability where unauthenticated $_POST['redirect_url'] could redirect users to external malicious sites after successful login.

Changes

  • Added isValidRedirectUrl() validation method that only permits relative URLs starting with /, blocks protocol-relative URLs (//example.com), and rejects malicious patterns (@, \)
  • Updated login() method to validate redirect URL before using it, falling back to /admin/dashboard if validation fails

Example

// Before: Direct usage of unvalidated user input
$RedirectUrl = $_POST['redirect_url'] ?? '/admin/dashboard';
header( 'Location: ' . $RedirectUrl );

// After: Validation prevents open redirect
$requestedRedirect = $_POST['redirect_url'] ?? '/admin/dashboard';
$RedirectUrl = $this->isValidRedirectUrl( $requestedRedirect )
    ? $requestedRedirect
    : '/admin/dashboard';
header( 'Location: ' . $RedirectUrl );

Attacker-supplied URLs like https://evil.com or //phishing-site.com will now be rejected, defaulting to the safe dashboard route.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Note

Free review on us!

CodeRabbit is offering free reviews until Fri Nov 07 2025 to showcase some of the refinements we've made.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 2 commits November 6, 2025 21:43
Co-authored-by: ljonesfl <1099983+ljonesfl@users.noreply.github.com>
Co-authored-by: ljonesfl <1099983+ljonesfl@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on authentication system PR Fix open redirect vulnerability in login controller Nov 6, 2025
Copilot AI requested a review from ljonesfl November 6, 2025 21:45
Copilot finished work on behalf of ljonesfl November 6, 2025 21:45
@ljonesfl ljonesfl marked this pull request as ready for review November 6, 2025 22:00
@ljonesfl ljonesfl merged commit c5e0ae9 into feature/auth Nov 9, 2025
1 of 2 checks passed
@ljonesfl ljonesfl deleted the copilot/sub-pr-1 branch November 9, 2025 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants