|
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 |
lws-loginWhen captcha_ratelimit works in sequence with authentication interceptors like lws-login, unauthenticated public guests must endure the captcha delays prior to attempting log-in operations or browsing unauthenticated domains. If a user is already fundamentally logged into your application ecosystem, repeatedly forcing a captcha check hinders experience.
The captcha_ratelimit handles this natively. Using its injected JavaScript context (lws_interceptor_path), the client-side captcha.js script queries the upstream lws-login's /.lws-login-status JSON endpoint directly. If the upstream interceptor confirms the session is already authenticated, the JavaScript immediately bypasses the captcha interaction (post-delay-ms and pre-delay-ms penalties) by dynamically appending a ?bypass=1 URI argument to the captcha submission, saving configurations such as explicitly mapping lws-login cryptographic secrets redundantly in the captcha_ratelimit vhost options.
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./.