Skip to content

Conversation

@sylwia-budzynska
Copy link

@sylwia-budzynska sylwia-budzynska commented Nov 18, 2024

Proposed changes in this pull request:

  • change the login page to redirect to settings.DEFAULT_PAGE instead of to the next parameter, which can be user-controlled. Please see GHSL-2024-288 (issue 5 in the report) for more information.

  • PR is based on the DEVELOP branch

  • Don't send big changes all at once. Split up big PRs into multiple smaller PRs that are easier to manage and review

  • Read contribution guide

Summary by CodeRabbit

  • New Features

    • Simplified login redirect logic to always direct users to the default page after login attempts.
  • Bug Fixes

    • Maintained error message handling for login attempts without changes.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

Walkthrough

The LoginHandler class in sickchill/views/authentication.py has been modified to simplify the user redirection logic after a login attempt. The redirect URL is now hardcoded to a default page, specifically "/" + settings.DEFAULT_PAGE + "/", rather than being determined by the "next" query parameter. The handling of login errors remains unchanged, and there are no modifications to the LogoutHandler class.

Changes

File Change Summary
sickchill/views/authentication.py Modified LoginHandler.post method to hardcode redirect to "/" + settings.DEFAULT_PAGE + "/". No changes to LogoutHandler.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LoginHandler
    participant Settings

    User->>LoginHandler: Submit login form
    LoginHandler->>LoginHandler: Authenticate user
    alt Successful authentication
        LoginHandler->>Settings: Retrieve DEFAULT_PAGE
        LoginHandler-->>User: Redirect to "/" + DEFAULT_PAGE + "/"
    else Failed authentication
        LoginHandler-->>User: Render login page with error message
    end
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
sickchill/views/authentication.py (2)

Line range hint 9-13: Critical: GET method still vulnerable to open redirect

While the POST method has been secured, the GET method still uses the user-controlled 'next' parameter for redirection, leaving it vulnerable to the same security issue.

Apply this fix to make it consistent with the POST method:

    def get(self, next_=None):
-        next_ = self.get_query_argument("next", next_)
        if self.get_current_user():
-            self.redirect(next_ or "/" + settings.DEFAULT_PAGE + "/")
+            self.redirect("/" + settings.DEFAULT_PAGE + "/")
        else:
            t = PageTemplate(rh=self, filename="login.mako")
            self.finish(t.render(title=_("Login"), header=_("Login"), topmenu="login", login_error=login_error))

Line range hint 7-30: Consider additional security improvements

While the open redirect fix is good, there are several security-related improvements to consider:

  1. The login_error global variable could lead to race conditions in concurrent scenarios
  2. Direct password comparison might be vulnerable to timing attacks
  3. Consider adding rate limiting for failed login attempts

Suggested improvements:

  1. Move login_error to session storage
  2. Use constant-time comparison for passwords
  3. Implement rate limiting based on the IP logging you already have

Would you like me to provide implementation examples for any of these security improvements?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 97328b0 and efbc781.

📒 Files selected for processing (1)
  • sickchill/views/authentication.py (1 hunks)
🔇 Additional comments (1)
sickchill/views/authentication.py (1)

31-31: Security fix looks good!

The change correctly addresses the open redirect vulnerability by removing the user-controlled redirect parameter and using a hardcoded default page instead.

@miigotu
Copy link
Contributor

miigotu commented Nov 29, 2024

User controllable variables are fine. No matter what you put in there you can't access SC without logging in. It's a single user system.

If I'm wrong about that, show me how you can access anything without logging in or using a cookie or bypass method outside of this parameter. IMHO this is a false positive.

@sylwia-budzynska
Copy link
Author

User controllable variables are fine. No matter what you put in there you can't access SC without logging in. It's a single user system.

This issue does not lead to an attacker accessing anything without logging in. This issue allows for redirecting a user to an attacker-controlled website and could be used in phishing attempts. The impact and PoC for this issue is described in the report I sent to you via email in issue number 5. I don't want to share more details in here, because it would be not in line with coordinated disclosure policy.

If I'm wrong about that, show me how you can access anything without logging in or using a cookie or bypass method outside of this parameter. IMHO this is a false positive.

I take that SC gets a lot of bogus reports. This is a real bug (see PoC in the report), but it does not lead to accessing anything without logging in. That said, if you don't consider this a bug, feel free to close this PR.

@miigotu
Copy link
Contributor

miigotu commented Dec 10, 2024

I'll accept the PR, but there is no way an attacker can exploit this without a login. If you can't login, the next parameter can't be used by anyone.

@miigotu miigotu merged commit c7128a8 into SickChill:develop Dec 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants