Commit graph

11 commits

Author SHA1 Message Date
0b0a9c7aaa ddos: use csprng for tokens 2025-11-23 17:48:57 -03:00
9dd95c82a7 move more things to test ngx 2025-11-23 17:26:54 -03:00
37e9af217f use metatable so ngx.shared is created dynamically 2025-11-23 17:23:21 -03:00
4795879278 configure shared maps globally 2025-11-23 17:23:00 -03:00
Claude
fbe238d3c1 Add mock resty.sha256 and resty.string for testing
The test environment doesn't have OpenResty libraries, so we need
to provide mock implementations for testing.

Created:
- tests/mock_resty_sha256.lua: Uses system sha256sum command to
  compute SHA-256 hashes. Mimics the resty.sha256 API (new,
  update, final).

- tests/mock_resty_string.lua: Implements to_hex() to convert
  binary strings to hexadecimal.

Updated test.lua to preload these mocks so that when the module
or tests require 'resty.sha256' or 'resty.string', they get our
mock implementations instead.

This allows the PoW verification tests to run and actually verify
the SHA-256 proof-of-work.
2025-11-23 17:19:07 -03:00
Claude
d8b1b861ab Add debug logging to diagnose token validation failures
Added debug logging to see what's happening with cookie header
parsing in the failing token validation tests. This will help
identify whether:
- ngx.req.get_headers() is returning the expected headers
- The Cookie header is being found (case sensitivity check)
- The token is being extracted correctly
- The token is found in the shared dict

Also added ngx log level constants (DEBUG, INFO, WARN, ERR) to
the test framework since the module uses them.
2025-11-23 17:19:07 -03:00
Claude
40072ec6ff Add DDoS protection challenge module with honeypot
Implements a Cloudflare-style "Under Attack" mode that protects against
DDoS attacks, scraping, and automated bots.

Features:
- Challenge-response system requiring human interaction
- Honeypot link that automatically bans IPs of bots that click it
- Cookie-based token system for validated users (24h default)
- Temporary IP banning (1h default)
- Comprehensive test suite

The module intercepts requests before they hit the backend, reducing
computational cost from scraping and DDoS attempts. It's particularly
effective against simple scrapers and volumetric attacks.

Files added:
- scripts/ddos_protection_challenge.lua - Main module implementation
- tests/ddos_protection_challenge.lua - Comprehensive test suite
- scripts/ddos_protection_challenge.README.md - Full documentation
- conf.example.ddos_protection.lua - Example configuration
- test.lua - Added test import
2025-11-23 17:19:07 -03:00
7f8e86fbd8 lint pass 2023-10-26 22:19:08 -03:00
2d2a68b1c3 validate schema on module tests 2022-12-07 15:26:11 -03:00
fd59059101 add draft for config schema validation 2022-12-07 14:57:07 -03:00
5d21c975ea add test suite 2022-12-06 15:53:20 -03:00