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

Method Not Allowed (GET): /admin/logout/ #536

Closed
8bitaby opened this issue Mar 5, 2024 · 6 comments
Closed

Method Not Allowed (GET): /admin/logout/ #536

8bitaby opened this issue Mar 5, 2024 · 6 comments
Labels
bug Something isn't working Duplicate A duplicate issue / PR

Comments

@8bitaby
Copy link

8bitaby commented Mar 5, 2024

While logging out the admin, rather than performing a POST the template performs a GET operation which raises an error saying:

Method Not Allowed (GET): /admin/logout/
Method Not Allowed: /admin/logout/
GET /admin/logout/ HTTP/1.1" 405 0

  • Issue is in /jazzmin/templates/admin/base.html --- and search for logout then,

  • change this
    <a href="{% url 'admin:logout' %}" class="dropdown-item">
    <i class="fas fa-users mr-2"></i> {% trans 'Log out' %}
    </a>

  • to this
    <form action="{% url 'admin:logout' %}" method="post">
    {% csrf_token %}
    <button type="submit" class="dropdown-item">
    <i class="fas fa-users mr-2"></i> {% trans 'Log out' %}
    </button>
    </form>

8bitaby added a commit to 8bitaby/django-jazzmin that referenced this issue Mar 5, 2024
Update logout function in base.html

This commit updates the logout functionality in the base template (`base.html`) to improve security and adhere to best practices. The previous implementation used a simple link for logout, which could be susceptible to cross-site request forgery (CSRF) attacks. 

The updated code replaces the logout link with a form submission method, utilizing the POST request with CSRF protection. This approach enhances the security of the logout functionality by ensuring that requests to the logout URL are only accepted from authorized sources, preventing potential unauthorized access or malicious actions.

Additionally, the use of a form submission method allows for better compatibility with server-side processing and future scalability. The form includes a CSRF token to mitigate CSRF attacks, providing an additional layer of security.

By making this change, we are prioritizing security and robustness in our application's authentication mechanisms, aligning with industry best practices and ensuring a safer user experience.

This commit addresses issue farridav#536  and implements the recommended solution. Tested locally to ensure proper functionality.
@sa11erto5n
Copy link

the view:

def logout_user(request):
    logout(request)
    return redirect('admin:index')

the modified line of base.html:
<a href="{% url 'jazzmin_dev:logout' %}" class="dropdown-item">

@jamesgilmorelyst jamesgilmorelyst added bug Something isn't working Duplicate A duplicate issue / PR labels Mar 23, 2024
@jamesgilmorelyst
Copy link

Hi @8bitaby, a PR was merged today (#544) to fix this issue. A new release will be needed to release this fix.

@jumaantony
Copy link

jumaantony commented Mar 26, 2024

@jamesgilmorelyst When will this be sorted? I have just installed the new version but still it aint wworking as working expected. Throwing the same error

@ExcelentProgrammer
Copy link

@sriraj66
Copy link

i am also getting the same error

Method Not Allowed: /admin/logout/
2024-04-18 20:39:06,142 - 61980 - log.py-log:241 - WARNING: Method Not Allowed: /admin/logout/
[18/Apr/2024 20:39:06] "GET /admin/logout/ HTTP/1.1" 405 0

@PacificGilly
Copy link
Collaborator

Apologies for the delay, but we've release the fix to resolve the logout issue now:

If you are still supporting an older version of Python (<3.8) or Django (<4) then we also have release a fix for this version as well:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Duplicate A duplicate issue / PR
Projects
None yet
Development

No branches or pull requests

7 participants