Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

The LoginController uses unsanitized $_GET['redirect'] and $_POST['redirect_url'] parameters directly in header() redirects, allowing attackers to redirect authenticated users to external malicious sites.

Changes

  • Added isValidRedirectUrl() private method to validate redirect URLs:

    • Rejects URLs with schemes (http://, https://, javascript:, data:, etc.)
    • Rejects protocol-relative URLs (//evil.com)
    • Only allows internal paths starting with /
    • Falls back to /admin/dashboard for invalid URLs
  • Updated showLoginForm() to validate $_GET['redirect'] before passing to view

  • Updated login() to validate $_POST['redirect_url'] before redirect

private function isValidRedirectUrl( string $url ): bool
{
    if( empty( $url ) )
    {
        return false;
    }
    
    // Reject URLs with schemes (http://, https://, javascript:, etc.)
    if( preg_match( '#^[a-z][a-z0-9+.-]*:#i', $url ) )
    {
        return false;
    }
    
    // Reject protocol-relative URLs (//example.com)
    if( str_starts_with( $url, '//' ) )
    {
        return false;
    }
    
    return str_starts_with( $url, '/' );
}

✨ 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:53
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 and user management Fix open redirect vulnerability in LoginController Nov 6, 2025
Copilot AI requested a review from ljonesfl November 6, 2025 21:56
Copilot finished work on behalf of ljonesfl November 6, 2025 21:56
@ljonesfl ljonesfl marked this pull request as ready for review November 6, 2025 21:59
@ljonesfl ljonesfl merged commit 1c6126c into feature/auth Nov 6, 2025
1 of 2 checks passed
@ljonesfl ljonesfl deleted the copilot/sub-pr-1-another-one branch November 6, 2025 21:59
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