Skip to content
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

[PLA-1864] Remove csrf cookie meta and use cookie instead #127

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

enjinabner
Copy link
Contributor

@enjinabner enjinabner commented Jun 20, 2024

PR Type

Enhancement, Bug fix


Description

  • Removed CSRF token handling from the API service, simplifying request logic.
  • Eliminated calls to ApiService.reloadCsrf in various parts of the application, including during login, logout, and account deletion.
  • Removed the CSRF token meta tag from the HTML head.

Changes walkthrough 📝

Relevant files
Enhancement
Settings.vue
Remove CSRF reload call after account deletion.                   

resources/js/components/pages/Settings.vue

  • Removed call to ApiService.reloadCsrf after account deletion.
+0/-1     
index.ts
Remove CSRF token handling from API service.                         

resources/js/api/index.ts

  • Removed fetching CSRF token from meta tag.
  • Adjusted request handling to remove CSRF token logic.
  • Simplified retry logic for 419 status code.
  • +1/-6     
    index.ts
    Remove CSRF reload calls during login and logout.               

    resources/js/store/index.ts

    • Removed calls to ApiService.reloadCsrf during login and logout.
    +0/-2     
    app.blade.php
    Remove CSRF token meta tag from HTML head.                             

    resources/views/app.blade.php

    • Removed CSRF token meta tag from HTML head.
    +1/-2     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @enjinabner enjinabner self-assigned this Jun 20, 2024
    @github-actions github-actions bot added enhancement New feature or request Bug fix labels Jun 20, 2024
    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review [1-5] 3
    🧪 Relevant tests No
    🔒 Security concerns CSRF Vulnerability:
    Removing CSRF tokens and related handling might expose the application to CSRF attacks unless alternative protections are implemented. Ensure that the application's security is not compromised by these changes.
    ⚡ Key issues to review CSRF Protection Removal:
    The removal of CSRF token handling and the CSRF meta tag could potentially expose the application to CSRF attacks if not properly mitigated elsewhere. Ensure that the application has alternative security measures in place to protect against such vulnerabilities.
    Dependency on CSRF Token:
    Ensure that no other parts of the application still depend on the CSRF token being present in the meta tags or being sent as a header in requests.

    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Security
    Ensure secure CSRF token handling for non-multi-tenant configurations

    Since the CSRF token handling was removed from the meta tag, ensure that the CSRF token is
    properly managed elsewhere, especially for non-multi-tenant configurations. Consider
    implementing a secure method to handle CSRF tokens if not already done.

    resources/js/api/index.ts [47-48]

     if (!useAppStore().isMultiTenant) {
         headers.Authorization = useAppStore().config.authorization_token;
    +    // Ensure CSRF token is added here if necessary
     }
     
    Suggestion importance[1-10]: 9

    Why: This suggestion addresses a significant security concern by ensuring that CSRF tokens are properly managed, which is crucial for preventing CSRF attacks in non-multi-tenant configurations.

    9
    Verify CSRF token handling after user logout to maintain session security

    Removing the CSRF reload might affect the session's security, especially after logout.
    Verify if CSRF protection is adequately handled after these operations.

    resources/js/store/index.ts [236-237]

     clearLogin() {
         this.user = null;
    +    // Consider handling CSRF token refresh here if necessary
     }
     
    Suggestion importance[1-10]: 8

    Why: Ensuring CSRF token handling after logout is crucial for maintaining session security. This suggestion highlights the need to verify that CSRF protection is not compromised by the removal of the CSRF reload.

    8
    Possible bug
    Prevent potential infinite recursion on handling 419 status code

    The recursive call to this.request when a 419 status code is received could lead to
    infinite recursion if not carefully managed. Consider adding a condition to limit the
    number of retries or handle this scenario differently.

    resources/js/api/index.ts [63]

     if (resp.status === 419 && nest && useAppStore().isMultiTenant) {
    -    return this.request({ url, method, data, headers });
    +    // Add a retry limit or alternative handling to prevent potential infinite recursion
     }
     
    Suggestion importance[1-10]: 8

    Why: This suggestion is important for preventing potential infinite recursion, which could lead to stack overflow errors and application crashes. Adding a retry limit or alternative handling is a prudent measure.

    8
    Maintainability
    Ensure front-end components have access to CSRF tokens after meta tag removal

    Ensure that removing the CSRF meta tag does not impact front-end components that rely on
    this meta tag for CSRF token values. Consider providing an alternative way to access the
    CSRF token in JavaScript if needed.

    resources/views/app.blade.php [6]

     <title>Enjin Platform</title>
    +<!-- Ensure alternative CSRF token handling here if required -->
     
    Suggestion importance[1-10]: 7

    Why: This suggestion is important for maintainability, ensuring that front-end components relying on the CSRF meta tag are not affected by its removal. Providing an alternative way to access the CSRF token is a good practice.

    7

    @enjinabner enjinabner merged commit e4226d3 into master Jun 26, 2024
    3 checks passed
    @enjinabner enjinabner deleted the feature/pla-1864/improve-csrf-cookie branch June 26, 2024 03:34
    enjinabner added a commit that referenced this pull request Jun 26, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Development

    Successfully merging this pull request may close these issues.

    2 participants