|
libwebsockets
Lightweight C library for HTML5 websockets
|
This plugin provides a simple interceptor mechanism based on a time delay (rate limit). It is designed to be used with the LWS interceptor_path mount option.
When a user accesses a protected mount, LWS checks for a valid JWT cookie. If the cookie is missing or invalid, the request is diverted to the interceptor_path. This plugin, when mounted at interceptor_path, serves a simple HTML page with a button.
Both before, and after when the user clicks the button, the plugin enforces a configurable wait. After the wait, it issues a signed JWT cookie valid for a configured duration (default 10 minutes) and redirects the user back to the original URL.
Ensure protocol_lws_captcha_ratelimit is enabled in your build.
The plugin is configured via per-vhost options (PVOs) under the protocol name lws_captcha_ratelimit.
| Option | Description | Default |
|---|---|---|
jwt-issuer | The issuer claim (iss) for the JWT. | "lws" |
jwt-audience | The audience claim (aud) for the JWT. | "lws" |
jwt-alg | The signing algorithm. | "HS256" |
jwt-expiry | Validity duration of the JWT in seconds. | 600 (10 mins) |
cookie-name | The name of the cookie to set/check. | "lws_captcha_ratelimit" |
jwt-jwk | Required. Path to a file containing the JWK (JSON Web Key) or the JWK JSON itself. | - |
asset-dir | Path to interceptor assets (CSS, JS, images). Use file:// prefix for local paths. | - |
pre-delay-ms | Delay before "Continue" button appears. | 5000 |
post-delay-ms | Delay after "Continue" button is pressed. | 3000 |
status | Status message to display. | "ok" |
stats-logging | Whether to emit once-a-minute status logging | 0 |
JWK Generation:
The JWK can be produced by lws-crypto-jwk -t OCT.
Example JWK (captcha-key.jwk):
In your JSON configuration (e.g., vhosts), configure the protected mount with interceptor-path pointing to the mount handled by this plugin.
Example localhost vhost config:
Note that you should not use the provided example jwt-jwk in production. You can regenerate one with lws-crypto-jwk -t OCT and copy it into place in the config.
In this example:
/ (and subpaths) are checked for a valid JWT./captcha./captcha is handled by the lws_captcha_ratelimit protocol./.