How to Block Bots using User-Agents in Python and FastAPI

How to Block Bots using User-Agents in Python and FastAPI

Tiempo de lectura: < 1 minutoWe will learn today how to implement a bot blocker using user-agents. 1. Install the library pip install user-agents 2. Creating the decorator file # dependencies/bot_detection.py import functools from fastapi import Request, HTTPException from user_agents import parse def block_bots(func): @functools.wraps(func) async def wrapper(request: Request, *args, **kwargs): ua_string = request.headers.get(“user-agent”, “”) ua = parse(ua_string) if ua.is_bot: … Read more

Creating an RSA Key for Jenkins and GitLab

Creating an RSA Key for Jenkins and GitLab

Tiempo de lectura: 2 minutosYou explain how to add an RSA key in Jenkins to authenticate with GitLab: In the Jenkins server (or your local machine), execute: bash ssh-keygen -t rsa -b 4096 -C “[email protected]” Save the keys, for example in ~/.ssh/id_rsa_jenkins. In a Pipeline (Jenkinsfile): groovy pipeline { agent any stages { stage(‘Checkout’) { steps { git credentialsId: … Read more

Blocking Bots with Cloudflare (Custom WAF Rule)

Blocking Bots with Cloudflare (Custom WAF Rule)

Tiempo de lectura: < 1 minutoYou often receive aggressive bot analysis on your websites. Today we are going to learn how to add rules in CloudFlare so that not many of them enter. This expression blocks: Basically: kills 90% of basic bot scraping / vuln scanners Paso 1: Enter Cloudflare Go to https://dash.cloudflare.com Select your domain Paso 2: Go to … Read more

Protecting Endpoints with Slowapi Step by Step in FastAPI

Protecting Endpoints with Slowapi Step by Step in FastAPI

Tiempo de lectura: < 1 minutoWe can implement Rate Limit for our calls using slowapi, which is the equivalent of Flask-Limiter but for FastAPI: bash pip install slowapi python # main.py from slowapi import Limiter, _rate_limit_exceeded_handler from slowapi.util import get_remote_address from slowapi.errors import RateLimitExceeded limiter = Limiter(key_func=get_remote_address) app.state.limiter = limiter app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) python # app/routers/users.py from slowapi import Limiter from … Read more

Activating DKIM for Enhanced Email Security and Spoof Prevention with OVH Cloud and Cloudflare

Activating DKIM for Enhanced Email Security and Spoof Prevention with OVH Cloud and Cloudflare

Tiempo de lectura: < 1 minutoDKIM es a security protocol that signs the emails on each delivery, this will allow us to authenticate the mail server that sends it. Enter into the OVH Manager Go to: Web Cloud → Emails → Domains → your-domain Choose the DKIM diagnosis: Pulsa en él y se activa. Before you activate it, they will … Read more

How to Create a Rate Limit System in PHP for Limiting Requests by IP: A Step-by-Step Guide

How to Create a Rate Limit System in PHP for Limiting Requests by IP: A Step-by-Step Guide

Tiempo de lectura: 2 minutosLearn how to protect your PHP server from abuse, bots or brute-force attacks by limiting the number of requests per second from each IP address. The Rate Limiting (or rate limiting) is a technique that allows to restrict the number of requests that a user (or IP) can make to a server within a time … Read more

Configuring Nginx Proxy Manager (npm) or Nginx to send the Real Client IP using Cloudflare Proxy

Configuring Nginx Proxy Manager (npm) or Nginx to send the Real Client IP using Cloudflare Proxy

Tiempo de lectura: < 1 minutoWe will learn today how we can capture the real IP of the client passing through Cloudflare’s proxy and receiving it in Nginx Proxy Manager (NPM) or Nginx. We will open our reverse proxy and go to Proxy Hosts. Now we select the proxy that we want to send real IPs and put it in … Read more