Web protection
Web protection is a set of checks es-python runs on every request your web application receives: who sent it, how often, whether it is framed in a way that can confuse a proxy, and what your application sent back. This page explains each check, how a client is identified, and how blocking works.
What web protection is
Web protection adds request-level checks to es-python, the kind a web application firewall makes, but from inside your application. Taint tracking follows attacker data to a dangerous operation; these checks look at the request and the response as a whole. Nothing is on until you switch it on, on the Filters page for your whole account or in a machine's Configure window for one machine.
A running program picks up a change within about 30 seconds. The one exception is a program that was started while every taint source and every web protection setting was off: it runs without the request checks, so after turning web protection on for the first time, restart it once.
The checks run in applications built on Django, Flask, FastAPI and other Starlette applications, and aiohttp. Each finding is reported as an event on the es-python list, with the source http, so rules can show, hide, drop or raise on it like any other event.
| Setting | What it does | On by default |
|---|---|---|
| Who sent the request | Picks the client address every other check uses | Header X-Forwarded-For |
| Rate limit | Refuses (or reports) a client sending too many requests | Off |
| Blocked clients | Refuses every request from an address on your list | Off |
| Checks | Reports ambiguous requests, reflected input, open redirects, forged host names, card numbers in responses and missing security headers | Off |
| Add missing security headers | Adds the safe security headers your app's responses leave out | Off |
| Request on each event | Attaches the client, method and path to events | On |
| Routes | Lists the routes your application serves, beside the events on each | Off |
Who sent the request
Every check counts, blocks and reports a request under one client address. By default es-python reads it from the X-Forwarded-For header, which a load balancer or reverse proxy adds; you can name a different header, or use the address of the connection itself.
- A request header (the default). Each proxy appends the address it saw to the right of the header, so the right-most entries were written by your own proxies and the left-most one is whatever the client claimed. es-python reads the header from the right, passing over the addresses of your own proxies, and the first address that is not one of them is the client. Set Proxies in front to the number of proxies between the internet and your application: with one load balancer, keep 1. If the header is missing, the connection address is used instead.
- Header name. Any header your proxy sets, for example
X-Real-IP,CF-Connecting-IPorTrue-Client-IP. A single-address header works the same way, andForwarded(RFC 7239) is read from itsfor=part. - The connection address. The address of the machine that opened the connection. Choose this when nothing sits in front of your application. Behind a proxy it would be the proxy's address for every visitor.
Your proxies
The header is read only on requests that arrive from one of your own proxies. Loopback, private (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7) and link-local addresses always count as yours, which covers a load balancer or reverse proxy inside your network. A request from any other address is counted, blocked and reported under that connection address, whatever header it carries, so a visitor cannot pick the address they are known by.
If a proxy reaches your application from a public address, such as a CDN that connects to it directly, list its published ranges under Your proxies' addresses, comma separated, for example 192.0.2.0/24, 2001:db8::/32. Up to 64 entries; each range may be at most a /8 (IPv4) or a /16 (IPv6). Listing a CDN that sits in front of your load balancer also lets es-python pass over the CDN's address in the header, the same as raising Proxies in front by one.
Rate limit
The rate limit refuses a client that sends more than a set number of requests within a set number of seconds, with 429 Too Many Requests and a Retry-After header. The default is 100 requests per 60 seconds. Set the action to Report only to record the event without refusing anything.
The count slides across time rather than resetting on a fixed clock, so a client cannot send twice the limit by timing requests around a boundary. Each client is reported once per window, as a rate limit event.
An IPv6 client is counted per /64 network, the block a single connection is usually given, so a client cannot reset its count by changing addresses within it.
The count is kept in each application process. If your server runs four worker processes, a client can send up to four times the limit before every worker has refused it. Set the limit with that in mind, or keep a separate limit at your load balancer for exact totals.
Refusing requests is part of Raise: while the rate limit blocks, the machine is billed at the Raise rate.
Blocked clients
The blocked clients list holds the addresses and ranges your application refuses, with 403 Forbidden, before your code runs. It is one list for your whole account, kept on the Filters page; switch Blocked clients to Refuse listed clients for the account or for one machine to enforce it.
Add an address such as 203.0.113.7 or a range such as 203.0.113.0/24, with an optional note and an expiry. A range wider than a /8 (IPv4) or a /32 (IPv6) is refused, so a typo cannot lock out everyone. You can also block a client straight from an event: open the event, and under Web request choose Block this client. A blocked client's first refusal in each minute is reported as a blocked client event.
A change reaches your machines within about 30 seconds. Enforcing the list is part of Raise: while it is on, the machine is billed at the Raise rate.
Auto-block
Auto-block adds a client to your blocked clients for a set number of hours after it does something only an attacker does. It is account-wide and off by default; while it is on, machines are billed at the Raise rate.
- Attack-shaped requests blocks a client whose request set off the ambiguous request or forged host name check. Ordinary visitors do not send conflicting body lengths or someone else's host name. A
reflected xssevent is reported and never blocks the client: it describes your page, and the request behind it may come from a visitor who followed someone else's link. - Also any high or critical event additionally blocks a client whose request led to a high or critical event. This catches more, but if ordinary traffic reaches a flaw in your application, ordinary visitors are blocked too. Use it once the events list is quiet.
Private, loopback and link-local addresses are never auto-blocked. When the client header is missing, es-python falls back to the connection address, which behind a proxy is the proxy itself, and blocking it would refuse everyone. An event that was made safe before it reached the risky call (suppressed) never triggers a block. Auto-blocked entries are marked auto in the list, expire on their own, and can be removed early.
Checks
Each check reports what it finds as an event and never refuses a request on its own. A Raise rule on an ambiguous request makes es-python refuse it with 400 (a body longer than its declared length is cut off at that length instead, since your application is already reading it); the response checks run after the response has been sent, so a Raise rule on them is recorded but cannot take the response back.
| Check | Event | Reports |
|---|---|---|
| Ambiguous requests | request smuggling |
A request with two different Content-Length values, both Content-Length and Transfer-Encoding, or an unusual Transfer-Encoding, and on ASGI servers a body longer than the Content-Length it declared. These are how request smuggling makes a proxy and your application disagree about where a request ends. |
| Reflected input | reflected xss, header injection |
A query parameter or part of the path carrying script that would run (a <script> element, an event handler inside a tag or after a quote, or a javascript: link) that appears unchanged in the HTML page your application returned. Escaped output does not match, and neither do plain tags such as </p> or <div> that pages already contain. Also a response header that contains a raw line break (response splitting), reported as header injection. |
| Open redirect | open redirect |
A redirect to another site that the request named, in a query parameter or in the path, including a value such as /evil.example that becomes //evil.example once your application puts a / in front of it. Redirects within your own host, and fixed redirects to a partner site, are not reported. |
| Forged host name | host header injection |
A request whose Host (or X-Forwarded-Host) is not one of your host names, when your application writes that name into a link or a redirect: how a password reset link gets pointed at an attacker's site. List your names in the field under the check, such as shop.example, *.shop.example; with no names the check cannot judge, so it stays off. The name is also recognised when your application writes it percent-encoded, and in crafted forms such as user@evil.example. |
| Card numbers in responses | card number in response |
A payment card number (it must pass the card checksum) in an HTML, text, JSON or XML response. A number the request itself sent is ignored, so a checkout page showing a visitor's own card back is not reported. The event shows the number masked to its first six and last four digits. Reported once an hour for each path. |
| Missing security headers | missing security header, cacheable private response |
An HTML page without Content-Security-Policy, X-Frame-Options (or a CSP frame-ancestors) or X-Content-Type-Options, plus Strict-Transport-Security on HTTPS. Each missing header is its own event, reported once an hour. Also a response to a signed-in request (an Authorization header or a session cookie) that a shared cache is allowed to keep, without that header in Vary, reported as cacheable private response once an hour for each path. |
Add missing security headers
When this is on, es-python adds these headers to your app's responses if your app has not set them:
| Header | Value | Added to |
|---|---|---|
X-Content-Type-Options |
nosniff |
every response with a content type |
X-Frame-Options |
SAMEORIGIN |
HTML pages, unless your Content-Security-Policy sets frame-ancestors |
Referrer-Policy |
strict-origin-when-cross-origin |
HTML pages |
Permissions-Policy |
camera=(), microphone=(), geolocation=() |
HTML pages |
Content-Security-Policy |
base-uri 'self'; object-src 'self'; frame-ancestors 'self' |
HTML pages |
Strict-Transport-Security |
max-age=31536000 |
every response with a content type, on requests that arrived over HTTPS |
Cross-Origin-Opener-Policy |
same-origin-allow-popups |
HTML pages |
Cross-Origin-Resource-Policy |
same-origin |
HTML pages |
X-Permitted-Cross-Domain-Policies |
none |
every response with a content type |
A header your app sets is never changed, whatever its value, so you can override any of these by setting it yourself. Responses with no body (204, 304) and responses without a content type are left as they are.
The added Content-Security-Policy names no script, style, image or connection source, so your pages load everything they load today. It keeps a <base> tag and plugin content (<object>, <embed>) to your own origin, and it allows framing by your own origin only. When your app sets X-Frame-Options itself, the frame-ancestors part is left out, so your own framing rule stays the one in force. For control over scripts and styles, set a Content-Security-Policy of your own.
Strict-Transport-Security tells a browser to use HTTPS for this host name for one year. It is added only when the request came over HTTPS (directly, or through a proxy that sends X-Forwarded-Proto: https), and it covers that one host name, not its subdomains. To end it early, have your app send Strict-Transport-Security: max-age=0.
A few kinds of page need their own header before you switch this on:
- A page that other sites embed in a frame needs your own
Content-Security-Policy: frame-ancestors ...(orX-Frame-Options) and your ownCross-Origin-Resource-Policy, or it gets the same-origin values. - A page that uses the camera, the microphone or the visitor's location needs your own
Permissions-Policy, or those stay off. - A page that shows a PDF or other plugin content from another site in an
<object>or<embed>, or uses a<base>tag pointing at another site, needs your ownContent-Security-Policy. - A page that another site opens as a popup and that talks back to it through
window.opener(a sign-in or payment window you provide) needs your ownCross-Origin-Opener-Policy: unsafe-none. Popups your own pages open keep working. - A host name that also serves plain HTTP on another port needs your own
Strict-Transport-Security.
"Headers your app sets" means the headers your application has set when its response leaves the framework. A header added later, by a proxy or a server in front of your app, is not seen.
With Missing security headers on as well, the check still reports what your app itself leaves out, and an event for a header es-python added says "(added by EyalSec)".
It is off until you switch it on, and it works for the same applications as the checks.
If a check fails
Web protection is designed never to break your application. If one of its checks runs into an error of its own, for example a response shape it does not expect or a setting it cannot read, your application serves the request as it would with web protection off, and a protection error event (graded Medium) names the protection that lapsed and the error. Each kind of error is reported once an hour for each application process.
A refusal (403, 429 or 400) only ever comes from a setting or a Raise rule you chose, never from an error. If protection error events keep appearing, write to support@eyalsec.com with one of them.
Request on each event
With Request on each event on, every event es-python reports while serving a web request carries that request: the client address, the address the connection came from when it differs, the method, the path with its query string, and the host. It is on by default, and only applies while some taint source is on, since without one there are no events to describe.
Query values whose names look like secrets (containing TOKEN, KEY, PASS, SECRET, AUTH, SESSION and similar) are replaced with [masked] on the machine and again when the event arrives, the same rule as the command line.
The event detail lists each request under Web request, with a Block this client button. One event keeps up to 500 distinct requests; after that it keeps counting the ones it has.
Routes
With Routes on, es-python keeps a list of the routes your application answered, how many requests each one had, and how many of its answers were errors, and sends it to EyalSec once a minute. The Web protection section of the Filters page lists them, with the number of events that happened on each.
The list shows what is reachable, which documentation does not always say: a route that answers traffic and has never been tested, or one that fails with 5xx far more than the rest. Variable parts of a path are folded, so /users/42 and /users/43 are one route, /users/{n}; FastAPI and Starlette routes use their own pattern, such as /items/{item_id}. Each application process keeps up to 500 routes and each machine up to 1,000.
Bot and firewall rules
Web protection's checks are the same for every request. To decide for yourself what happens to the requests you describe, such as blocking a scanner, challenging a suspicious visitor or slowing down a script, use bot and firewall rules. They run right after the blocked clients list and the rate limit, and their challenge page and captcha settings are described on that page.
Scope
Web protection works inside your application, so it sees the request your code actually received, after your proxies have done their work. Its scope:
- It protects only applications running under es-python on the frameworks above, and only traffic that reaches them. Floods that exhaust your network or your server before a request arrives need protection in front of the application.
- Rate limits count per process, as described above.
- The reflected input and open redirect checks read query parameters. A form body is not inspected.
- The response checks read the first 256 KB of each response.
- Django's test client calls Django's request handling directly, so these checks do not run under it.