mirror of
https://codeberg.org/Freedium-cfd/web.git
synced 2026-03-11 09:04:37 +00:00
misc: anti bot
This commit is contained in:
parent
49ab8d540f
commit
1fe36ab574
2 changed files with 42 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ from starlette.responses import Response, StreamingResponse
|
|||
from starlette.types import Message
|
||||
|
||||
from server import transponder_code_correlation, url_correlation, xkcd_passwd, xp, config, home_page_process
|
||||
from server.utils.anti_bot import filter_bots
|
||||
from server.utils.notify import send_message
|
||||
from server.utils.error import generate_error
|
||||
from server.utils.utils import string_to_number_ascii
|
||||
|
|
@ -28,6 +29,9 @@ async def get_body(request: Request) -> bytes:
|
|||
|
||||
class LoggerMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(self, request: Request, call_next: Callable[[Request], Awaitable[StreamingResponse]]) -> Response: # type: ignore
|
||||
if filter_bots(request.headers.get("User-Agent")):
|
||||
return Response(status_code=403)
|
||||
|
||||
start_time = time.time()
|
||||
generated_id = xp.generate_xkcdpassword(xkcd_passwd, delimiter="-", numwords=3)
|
||||
transponder_code = string_to_number_ascii(generated_id)
|
||||
|
|
|
|||
38
server/utils/anti_bot.py
Normal file
38
server/utils/anti_bot.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from loguru import logger
|
||||
|
||||
|
||||
bot_signatures = {
|
||||
"facebookexternalhit",
|
||||
"/apple-touch-icon",
|
||||
"Googlebot",
|
||||
"AdsBot-Google",
|
||||
"Google-Adwords-Instant",
|
||||
"Apache-HttpClient",
|
||||
"SafeDNSBot",
|
||||
"RevueBot",
|
||||
"MetaURI API",
|
||||
"redback/v",
|
||||
"Slackbot",
|
||||
"HTTP_Request2/",
|
||||
"python-requests/",
|
||||
"LightspeedSystemsCrawler/",
|
||||
"CipaCrawler/",
|
||||
"Twitterbot/",
|
||||
"Go-http-client/",
|
||||
"/cheese_service",
|
||||
"undici",
|
||||
"database",
|
||||
"node-fetch",
|
||||
"Java/",
|
||||
"axios/",
|
||||
"okhttp/",
|
||||
"go-resty/",
|
||||
"Faraday v",
|
||||
# "curl/"
|
||||
}
|
||||
|
||||
|
||||
def filter_bots(details: str) -> bool:
|
||||
is_bot = any(bot_signature in details for bot_signature in bot_signatures)
|
||||
logger.debug(f"{details} is a bot: {is_bot}")
|
||||
return is_bot
|
||||
Loading…
Reference in a new issue