Skip to content

[WEB-4943] refactor: streamline URL construction in authentication views#7806

Merged
sriramveeraghanta merged 3 commits intopreviewfrom
fix-space-redirections
Sep 16, 2025
Merged

[WEB-4943] refactor: streamline URL construction in authentication views#7806
sriramveeraghanta merged 3 commits intopreviewfrom
fix-space-redirections

Conversation

@pablohashescobar
Copy link
Member

@pablohashescobar pablohashescobar commented Sep 16, 2025

Description

  • Updated MagicSignInSpaceEndpoint and MagicSignUpSpaceEndpoint to directly construct redirect URLs using formatted strings instead of the get_safe_redirect_url function.
  • Enhanced get_safe_redirect_url to use quote for safer URL encoding of parameters.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Test Scenarios

  • test all space authentication for correct redirection

References

WEB-4943

Summary by CodeRabbit

  • Bug Fixes

    • Resolved inconsistent post-login redirects across Email, GitHub, GitLab, Google, and Magic Link sign-ins, ensuring reliable navigation to the intended page and avoiding double slashes in URLs.
    • Standardized error-redirect behavior for a more predictable experience.
  • Security

    • Strengthened validation of post-login redirect paths to prevent unsafe or malformed redirects.
  • Refactor

    • Unified redirect construction across authentication flows for consistency and maintainability without changing user-facing behavior.

* Updated MagicSignInSpaceEndpoint and MagicSignUpSpaceEndpoint to directly construct redirect URLs using formatted strings instead of the get_safe_redirect_url function.
* Enhanced get_safe_redirect_url to use quote for safer URL encoding of parameters.
Copilot AI review requested due to automatic review settings September 16, 2025 11:57
@pablohashescobar pablohashescobar marked this pull request as draft September 16, 2025 11:57
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 16, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Replaces successful post-auth redirect construction across space auth views to validate next_path and concatenate with base_host(...).rstrip("/"). Retains get_safe_redirect_url only for error paths. Updates get_safe_redirect_url in path_validator to always emit next_path as a query param and avoid mutating params.

Changes

Cohort / File(s) Summary
Space auth views – success redirect changes
apps/api/plane/authentication/views/space/email.py, .../space/github.py, .../space/gitlab.py, .../space/google.py, .../space/magic.py
Import validate_next_path. On successful auth, sanitize next_path via validate_next_path and build redirect as base_host(request, is_space=True).rstrip("/") + next_path. Previous use of get_safe_redirect_url for success paths removed. Error paths continue using get_safe_redirect_url.
Path validator refactor
apps/api/plane/utils/path_validator.py
get_safe_redirect_url now rstrips base_url, always includes next_path as a separate query param, and uses urlencode(params) without mutating inputs. Added quote import; minor formatting cleanup. validate_next_path behavior unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant V as Space Auth View
  participant PV as Path Validator
  participant H as base_host()

  U->>V: Successful auth (email/github/gitlab/google/magic)
  V->>PV: validate_next_path(next_path)
  PV-->>V: sanitized_next_path
  V->>H: base_host(request, is_space=true)
  H-->>V: https://space.example.com/
  V-->>U: Redirect to base_host.rstrip("/") + sanitized_next_path
  note over V,U: Error paths still use get_safe_redirect_url(base_url, next_path, params)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ready to merge

Suggested reviewers

  • dheeru0198
  • sriramveeraghanta

Poem

A hop, a check, a sanitized trail,
No double slashes on the rail.
Paths now vetted, clean and tight,
Base meets next—redirects right.
I twitch my nose, approve the route,
Secure little hops—no doubt! 🐇✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-space-redirections

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf45635 and 8cd430b.

📒 Files selected for processing (6)
  • apps/api/plane/authentication/views/space/email.py (2 hunks)
  • apps/api/plane/authentication/views/space/github.py (2 hunks)
  • apps/api/plane/authentication/views/space/gitlab.py (2 hunks)
  • apps/api/plane/authentication/views/space/google.py (2 hunks)
  • apps/api/plane/authentication/views/space/magic.py (3 hunks)
  • apps/api/plane/utils/path_validator.py (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors URL construction in authentication views by replacing the get_safe_redirect_url function with direct string formatting for specific endpoints, while simultaneously enhancing the remaining get_safe_redirect_url function with safer URL encoding using the quote function.

  • Replaced get_safe_redirect_url calls with direct string formatting in MagicSignInSpaceEndpoint and MagicSignUpSpaceEndpoint
  • Enhanced get_safe_redirect_url to use quote for more secure URL parameter encoding
  • Streamlined URL construction logic in authentication flows

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/api/plane/utils/path_validator.py Enhanced get_safe_redirect_url with quote import and safer URL encoding
apps/api/plane/authentication/views/space/magic.py Replaced get_safe_redirect_url calls with direct string formatting

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

cursor[bot]

This comment was marked as outdated.

* Added validate_next_path function to improve the safety of redirect URLs in MagicSignInSpaceEndpoint and MagicSignUpSpaceEndpoint.
* Updated URL construction to ensure proper handling of next_path and base_url.
* Streamlined the get_safe_redirect_url function for better parameter encoding.
* Introduced validate_next_path function to enhance URL safety in SignInAuthSpaceEndpoint, SignUpAuthSpaceEndpoint, GitHubCallbackSpaceEndpoint, GitLabCallbackSpaceEndpoint, and GoogleCallbackSpaceEndpoint.
* Updated URL construction to directly format the redirect URL, improving clarity and consistency across multiple authentication views.
@pablohashescobar pablohashescobar changed the title refactor: streamline URL construction in authentication views [WEB-4943] refactor: streamline URL construction in authentication views Sep 16, 2025
@makeplane
Copy link

makeplane bot commented Sep 16, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@pablohashescobar pablohashescobar marked this pull request as ready for review September 16, 2025 13:11
@sriramveeraghanta sriramveeraghanta merged commit 4d17637 into preview Sep 16, 2025
10 of 13 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-space-redirections branch September 16, 2025 13:14

# Return the safe redirect URL
return f"{base_url.rstrip('/')}?{urlencode(params)}"
return f"{base_url}/?next_path={validated_path}"
Copy link

Choose a reason for hiding this comment

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

Bug: Redirect URL Malformed with Empty Path

The get_safe_redirect_url function now unconditionally adds ?next_path={validated_path} to the URL, even when validated_path is empty. This differs from the previous behavior of omitting the parameter for invalid paths, potentially creating malformed URLs like base_url/?next_path=. Additionally, validated_path is directly inserted without URL encoding, which could lead to issues with special characters.

Fix in Cursor Fix in Web

yarikoptic pushed a commit to yarikoptic/plane that referenced this pull request Oct 1, 2025
…ews (makeplane#7806)

* refactor: streamline URL construction in authentication views

* Updated MagicSignInSpaceEndpoint and MagicSignUpSpaceEndpoint to directly construct redirect URLs using formatted strings instead of the get_safe_redirect_url function.
* Enhanced get_safe_redirect_url to use quote for safer URL encoding of parameters.

* refactor: enhance URL validation and redirection in authentication views

* Added validate_next_path function to improve the safety of redirect URLs in MagicSignInSpaceEndpoint and MagicSignUpSpaceEndpoint.
* Updated URL construction to ensure proper handling of next_path and base_url.
* Streamlined the get_safe_redirect_url function for better parameter encoding.

* refactor: unify URL redirection logic across authentication views

* Introduced validate_next_path function to enhance URL safety in SignInAuthSpaceEndpoint, SignUpAuthSpaceEndpoint, GitHubCallbackSpaceEndpoint, GitLabCallbackSpaceEndpoint, and GoogleCallbackSpaceEndpoint.
* Updated URL construction to directly format the redirect URL, improving clarity and consistency across multiple authentication views.
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.

3 participants