NAME

PAGI::FastAPI::Middleware::BotProtection - Asynchronous Proof-of-Work Bot Protection Middleware for PAGI::FastAPI

VERSION

Version v1.0.0

SYNOPSIS

use PAGI::FastAPI;

my $app = PAGI::FastAPI->new();

# Register bot protection middleware
$app->add_bot_protection(
    difficulty => 3,
    secret     => $ENV{BOT_PROTECTION_SECRET},
    ttl        => 300,
);

DESCRIPTION

PAGI::FastAPI::Middleware::BotProtection integrates cryptographic Proof-of-Work bot mitigation into PAGI::FastAPI application request pipelines.

When active, incoming requests without a valid X-Bot-Challenge and X-Bot-Nonce header are rejected with an HTTP 401 Unauthorized response accompanied by challenge parameters in the response headers. Real client environments (such as web browsers executing background JavaScript) solve the puzzle and retry the request, bypassing automated bots and naive scrapers.

HEADERS

The middleware inspects and sets the following HTTP response/request headers:

  • x-bot-challenge (Request/Response)

    The HMAC-signed challenge token string issued by the server.

  • x-bot-difficulty (Response)

    The integer difficulty level assigned to the active challenge.

  • x-bot-nonce (Request)

    The integer solution nonce computed by the client.

SEE ALSO

PAGI::FastAPI::BotProtection::ProofOfWork, PAGI::FastAPI

AUTHOR

Mohammad Sajid Anwar, <mohammad.anwar at yahoo.com>

BUGS

Please report any bugs or feature requests through the web interface at https://github.com/manwar/PAGI-FastAPI/issues. I will be notified and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc PAGI::FastAPI::Middleware::BotProtection

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright (C) 2026 Mohammad Sajid Anwar.

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License (2.0).