You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simon987 40d2173fbd
Merge pull request #9 from alecpm/fix-content-type-header
4 months ago
.gitignore Embed SHA1 2 years ago
LICENSE Configuration options, tweak challenge, update readme 2 years ago Update 1 year ago Embed SHA1 (for real this time) 1 year ago
config Update readme & quick cleanup 2 years ago
ngx_http_js_challenge.c Explicitly set a content type header. 4 months ago
throughput.png Update readme & quick cleanup 2 years ago


GitHub CodeFactor

Demo website

Simple javascript proof-of-work based access for Nginx with virtually no overhead.

Easy installation: just add load_module /path/to/; to your nginx.conf file and follow the configuration instructions.


Simple configuration

server {
    js_challenge on;
    js_challenge_secret "change me!";

    # ...

Advanced configuration

server {
    js_challenge on;
    js_challenge_secret "change me!";
    js_challenge_html /path/to/body.html;
    js_challenge_bucket_duration 3600;
    js_challenge_title "Verifying your browser...";

    location /static {
        js_challenge off;
        alias /static_files/;

    location /sensitive {
        js_challenge_bucket_duration 600;

  • js_challenge on|off Toggle javascript challenges for this config block
  • js_challenge_secret "secret" Secret for generating the challenges. DEFAULT: "changeme"
  • js_challenge_html "/path/to/file.html" Path to html file to be inserted in the <body> tag of the interstitial page
  • js_challenge_title "title" Will be inserted in the <title> tag of the interstitial page. DEFAULT: "Verifying your browser..."
  • js_challenge_bucket_duration time Interval to prompt js challenge, in seconds. DEFAULT: 3600


  1. Add load_module; to /etc/nginx/nginx.conf
  2. Reload nginx -s reload

Build from source

These steps have to be performed on machine with compatible configuration (same nginx, glibc, openssl version etc.)

  1. Install dependencies
    apt install libperl-dev libgeoip-dev libgd-dev libxslt1-dev libpcre3-dev
  2. Download nginx tarball corresponding to your current version (Check with nginx -v)
    tar -xzf nginx-1.16.1.tar.gz
    export NGINX_PATH=$(pwd)/nginx-1.16.1/
  3. Compile the module
    git clone
    cd ngx_http_js_challenge_module
  4. The dynamic module can be found at ${NGINX_PATH}/objs/

Known limitations / TODO

  • Users with cookies disabled will be stuck in an infinite refresh loop (TODO: redirect with a known query param, if no cookie is specified but the query arg is set, display an error page)
  • If nginx is behind a reverse proxy/load balancer, the same challenge will be sent to different users and/or the response cookie will be invalidated when the user is re-routed to another server. (TODO: use the x-real-ip header when available)