Skip to main content
Menu
Advisories

Config Directive Validation Bypass via Data File Extensions Allows Injection of Blocked Directives

GHSA-VXXJ-X4X4-Q624Published Updated GitHub

Description

Files with data extensions (.pem, .key, .crt, .cer, .csr, .crl, .ca-bundle, .htpasswd) skip the config directive validation entirely, allowing any blocked directive to be written and then loaded via nginx include. This renders the entire blocklist security control useless — all 8 extensions bypass all blocked directives.

Details

nginx-ui implements a directive blocklist in internal/config/validation.go that prevents users from writing dangerous nginx directives (such as js_content, perl_set, lua_package_path) through the config editor API. The existence of this blocklist proves the maintainer considers authenticated users a threat to configuration integrity — otherwise there would be no reason to restrict what they can write.

However, files with data extensions (.pem, .key, .crt, .cer, .csr, .crl, .ca-bundle, .htpasswd) skip the directive validation entirely. At validation.go line 198:

if IsDataFile(path) {
    return ValidateDataContent([]byte(content))
}

ValidateDataContent only checks for binary/null bytes — it does not check for dangerous nginx directives.

Since the include directive is not blocked (and cannot be, as it is essential for nginx operation), an attacker can:

  1. Write any blocked directive into a file with a data extension (e.g., malicious.pem)
  2. Write a normal .conf file that includes the data file: include malicious.pem;
  3. nginx parses the included file as configuration regardless of its extension

This completely renders the entire directive blocklist useless. Even if individual entries are added to fix gaps, this architectural bypass remains functional. Every current and future blocklist entry can be circumvented through any of the 8 data file extensions.

Root Cause

FileLineIssue
internal/config/validation.go198IsDataFile() causes early return, skipping directive validation
internal/config/validation.go199ValidateDataContent() only checks for binary bytes, not directives
internal/config/validation.go131-167Blocklist exists but is architecturally bypassable

Extensions that bypass (8/8 tested)

.pem, .crt, .cer, .key, .csr, .crl, .ca-bundle, .htpasswd

Proof of concept

Step 1: Authenticate as any user (nginx-ui has no RBAC — all users are admin).

Step 2: Write a blocked directive (js_content) to a .pem file — blocklist bypassed:

POST /api/configs
Content-Type: application/json

{"name": "evil.pem", "base_dir": "", "content": "js_content exploit_handler;\n", "overwrite": true}

Result: HTTP 200 — blocklist bypassed!

Step 3: Verify the same directive IS blocked in a .conf file:

POST /api/configs

{"name": "evil.conf", "base_dir": "", "content": "server { location / { js_content exploit_handler; } }", "overwrite": true}

Result: HTTP 500 — blocked by directive validation.

Step 4: Write a .conf that includes the .pem:

POST /api/configs

{"name": "site.conf", "base_dir": "sites-available", "content": "server {\n    listen 8888;\n    include evil.pem;\n}", "overwrite": true}

Result: HTTP 200 — include is not blocked.

Step 5: Enable the site and run nginx -t — the blocked directive is now active in nginx's configuration.

All 8 data extensions tested and confirmed to bypass: .pem, .crt, .cer, .key, .csr, .crl, .ca-bundle, .htpasswd. Full automated PoC tested on Docker (nginx-ui latest).

Impact

  • Complete blocklist bypass: ALL blocked directives (js_*, perl_*, lua_package_path, etc.) can be injected through any of the 8 data file extensions
  • On systems with scripting modules (njs, Perl, Lua/OpenResty): Remote Code Execution
  • The blocklist provides zero actual protection against a deliberate attacker — it is security theater
  • Defense in depth failure: Even if every individual directive gap is patched, this bypass makes ALL future blocklist additions useless
  • The blocklist's existence proves the threat model: if authenticated users were fully trusted with configuration, there would be no blocklist. Its presence demonstrates the maintainer considers directive injection a threat worth blocking — this bypass defeats that control entirely.

Suggested Fix

Option A (recommended): Apply directive validation to all files regardless of extension:

// Always check for blocked directives, even in data files
if err := ValidateConfigDirectives(content); err != nil {
    return err
}
if IsDataFile(path) {
    return ValidateDataContent([]byte(content))
}

Option B: Validate included file content transitively — when a config references include <path>, validate the included file's content against the blocklist.

Option C: Restrict include to only allow .conf files that have passed validation.

Affected versions

References

GitHub · 0xJacky/nginx-ui