Ushka

ushka.security.verify

ushka verify: attack your own app and report what got through.

It sends hostile payloads (XSS, SQL injection, template injection, path traversal, open redirect, header injection, junk input) to every route, in the process, with no network, and checks what comes back. It can only reach the app object you give it, never another server.

Every probe ends in one of these:

  • blocked: refused by validation (422), the guard, or an HTTP error;
  • guard: the guard refused it inside your handler (the request would be a 500 for a real visitor, so sanitise there: the report shows the line to write);
  • handled: the request went through and the payload did no harm;
  • VULNERABLE: the payload did its job (reflected as markup, injected a header...);
  • crash: the handler raised on hostile input.

Only GET routes are probed by default, because probing runs your real handlers. include_writes also probes POST/PUT/PATCH/DELETE: point it at a test database.

Routes listed in [security] csrf_exempt_paths (webhooks, machine APIs) are probed with the same rules and marked as exempt in the report: they are the most exposed routes, so they most need the hostile input. skip_exempt leaves them out. The only thing not sent to them is the cross-site CSRF probe, because a route that is exempt on purpose answers it with a 200 and that would be a false alarm. The payload probes carry no cross-site headers, so the CSRF check can neither mask nor fake their result.

cookie and session_data probe as a logged-in visitor (a forged, correctly signed session cookie), which is how routes behind a login redirect are reached.

In this module

class Payload
class Finding
class Report
class Slot
def discover_slots()
def run()Probes every route of app and returns the Report.

class Payload

class Finding

to_dict

def to_dict() -> dict

class Report

add

def add(finding: Finding) -> None

Adds a finding unless the same problem on the same input is already there.

failing

def failing(fail_on: str = 'medium') -> list[Finding]

to_dict

def to_dict() -> dict

class Slot

def discover_slots

def discover_slots(
    method: str,
    raw_path: str,
    func: Callable,
    extra_params = (),
) -> list[Slot]

def run

async def run(
    app,
    include_writes: bool = False,
    extra_params = (),
    max_probes_per_route: int = 200,
    skip_exempt: bool = False,
    cookie: str = '',
    session_data: dict[str, Any] | None = None,
    headers: dict[str, str] | None = None,
) -> Report

Probes every route of app and returns the Report.

skip_exempt leaves out the routes exempt from CSRF. cookie (name=value, several joined with ; ), headers (sent with every request, e.g. Authorization) and session_data (forged into a signed session cookie) probe as a visitor who is logged in. Their values are never reported; only the keys of session_data are.