SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 2b480e6b authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Block weird search queries

parent b298f3cf
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ __license__ = "AGPL v3" ...@@ -4,6 +4,7 @@ __license__ = "AGPL v3"
import datetime import datetime
import pyotp import pyotp
import re
from django import forms from django import forms
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
...@@ -701,6 +702,10 @@ class SearchForm(HayStackSearchForm): ...@@ -701,6 +702,10 @@ class SearchForm(HayStackSearchForm):
if not self.cleaned_data.get("q"): if not self.cleaned_data.get("q"):
return self.no_query_found() return self.no_query_found()
# Block queries matching flagged regex to avoid gunicorn worker timeout
if re.search(r'\w{8,}.www.\w{7,}.cn', self.cleaned_data["q"]):
return self.no_query_found()
sqs = self.searchqueryset.auto_query(self.cleaned_data["q"]) sqs = self.searchqueryset.auto_query(self.cleaned_data["q"])
if self.load_all: if self.load_all:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment