Skip to content

Add middleware to ban bytedance user agent - #1347

Merged
TG1999 merged 2 commits into
aboutcode-org:mainfrom
TG1999:ban_bytedance_user_agent
Nov 27, 2023
Merged

Add middleware to ban bytedance user agent#1347
TG1999 merged 2 commits into
aboutcode-org:mainfrom
TG1999:ban_bytedance_user_agent

Conversation

@TG1999

@TG1999 TG1999 commented Nov 26, 2023

Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
@TG1999
TG1999 force-pushed the ban_bytedance_user_agent branch from a49a18e to da95d01 Compare November 26, 2023 21:55

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM... just a minor nit.

def process_request(self, request):
user_agent = request.META.get("HTTP_USER_AGENT", None)
if user_agent and "bytedance" in user_agent:
return HttpResponseForbidden("You are banned!", content_type="text/html")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do not provide insights to the spammer caller in this case.
Use a HttpResponseNotFound (404) instead fully empty and no message.

Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
@TG1999
TG1999 merged commit fca8815 into aboutcode-org:main Nov 27, 2023
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.

2 participants