Nginx HMAC Secure Link Module

Source: upstream source

Directives

Example

location ^~ /files/ {
    # The three comma-separated fields: token, timestamp, expires (seconds)
    secure_link_hmac "$arg_st,$arg_ts,$arg_e";

    # HMAC secret key
    secure_link_hmac_secret "my_secret_key";

    # The message that was signed: URI + timestamp + expiry
    secure_link_hmac_message "$uri|$arg_ts|$arg_e";

    # Hash algorithm
    secure_link_hmac_algorithm sha256;

    # In production, do not reveal whether the token was wrong or expired.
    # $secure_link_hmac == "1" → valid and not expired
    # $secure_link_hmac == "0" → valid but expired
    # $secure_link_hmac unset  → invalid / malformed
    if ($secure_link_hmac != "1") {
        return 403;
    }

    rewrite ^/files/(.*)$ /files/$1 break;
}

↑ back to index