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

WARNING::django.security.csrf::Forbidden (CSRF token from the 'X-Csrftoken' HTTP header incorrect.): /admin/autocomplete/search/ #194

Open
frague59 opened this issue Jan 9, 2025 · 1 comment

Comments

@frague59
Copy link

frague59 commented Jan 9, 2025

Hi,

I'm having CSRF issues with wagtailautocomplete, on my dev platform (not yet deployed).

My CSRF settings:

CSRF_COOKIE_SAMESITE = "Strict"
CSRF_COOKIE_SECURE = True
CSRF_USE_SESSIONS = False

I'm using a autocomplete_custom_queryset_filter() method to filter the queryset.

class Contact(models.Model):

   last_name = ...
   first_name = ...
   company = ...

   def autocomplete_label(self) -> str:
       return str(self)

   @staticmethod
   def autocomplete_custom_queryset_filter(search_term: str) -> QuerySet:
       return Contact.objects.filter(
           Q(first_name__icontains=search_term)
           | Q(last_name__icontains=search_term)
           | Q(company__icontains=search_term)
       )

The "client" model :

class EquipmentContact(models.Model):
    """M2M relation table."""
    contact = models.ForeignKey(Contact)
    ....
    panels = [
        AutocompletePanel("contact"),
        ...
    ]

What is weird is that I can see the X-CSRFToken in AJAX header AND the csrftoken in the cookies, but the request fails.

Django: 4.2.x
Wagtail: 6.3.2
wagtailautocomplete: 0.11.0

Thanks for your help !

@frague59
Copy link
Author

frague59 commented Jan 9, 2025

The request fails with a 403 status.

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

No branches or pull requests

1 participant