[GH-ISSUE #4965] [Bug]: Blank sign-in page after update to 3.2.8 due to blocked inline script by CSP #3484

Closed
opened 2026-10-31 20:32:46 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @ubelian on GitHub (Jun 5, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4965

Describe the bug

After updating 3x-ui to version from 3.2.6 to 3.2.8, the panel sign-in page opens as a blank white page.

The initial HTML loads successfully, the page title changes to "Sign in", and static JS/CSS assets return HTTP 200. However, React does not mount into #app.

Browser console shows that an inline script is blocked by Content-Security-Policy:

Content-Security-Policy: The page’s settings blocked an inline script (script-src-elem) because it violates the following directive: "script-src 'self' 'nonce-...'"

The blocked inline script appears to be the script that sets:
window.X_UI_BASE_PATH = "...";
window.X_UI_CUR_VER = "3.2.8";
window.X_UI_DB_TYPE = "sqlite";

As a result:
document.querySelector("#app").innerHTML
returns an empty string.


### How to reproduce the problem

1. Update 3x-ui to version 3.2.8.
2. Open the panel URL with a custom webBasePath.
3. The sign-in page loads, but the screen remains blank.
4. Open browser DevTools console.
5. Observe CSP error about blocked inline script.

### Expected behavior

The sign-in page should render normally.

### Actual behavior

The page stays blank. React app is not mounted.

### Relevant logs

```shell
Server logs look normal:
Starting x-ui 3.2.8
Web server running HTTPS on [::]:18143
XRAY: infra/conf/serial: Reading config: &{Name:bin/config.json Format:json}
Sub server running HTTPS on [::]:2096

Screenshots

No response

3x-ui version

3.2.8

Xray-core version

26.5.9

How did you install 3x-ui?

install.sh script

Operating system

Debian 13

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

Firefox 151 on Linux

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @ubelian on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4965 ### Describe the bug After updating 3x-ui to version from 3.2.6 to 3.2.8, the panel sign-in page opens as a blank white page. The initial HTML loads successfully, the page title changes to "Sign in", and static JS/CSS assets return HTTP 200. However, React does not mount into `#app`. Browser console shows that an inline script is blocked by Content-Security-Policy: ```text Content-Security-Policy: The page’s settings blocked an inline script (script-src-elem) because it violates the following directive: "script-src 'self' 'nonce-...'" The blocked inline script appears to be the script that sets: window.X_UI_BASE_PATH = "..."; window.X_UI_CUR_VER = "3.2.8"; window.X_UI_DB_TYPE = "sqlite"; As a result: document.querySelector("#app").innerHTML returns an empty string. ### How to reproduce the problem 1. Update 3x-ui to version 3.2.8. 2. Open the panel URL with a custom webBasePath. 3. The sign-in page loads, but the screen remains blank. 4. Open browser DevTools console. 5. Observe CSP error about blocked inline script. ### Expected behavior The sign-in page should render normally. ### Actual behavior The page stays blank. React app is not mounted. ### Relevant logs ```shell Server logs look normal: Starting x-ui 3.2.8 Web server running HTTPS on [::]:18143 XRAY: infra/conf/serial: Reading config: &{Name:bin/config.json Format:json} Sub server running HTTPS on [::]:2096 ``` ### Screenshots _No response_ ### 3x-ui version 3.2.8 ### Xray-core version 26.5.9 ### How did you install 3x-ui? install.sh script ### Operating system Debian 13 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) Firefox 151 on Linux ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:32:46 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 5, 2026):

Thanks for the detailed report. Here's what the code does and how to narrow this down.

How the CSP nonce works

The CSP security headers (including the script-src 'nonce-…' directive) were introduced in v3.0.2 via a security hardening commit. The mechanism works as follows, all within a single HTTP request:

  1. web/middleware/security.go generates a fresh random nonce with crypto/rand, stores it in the Gin context (c.Set("csp_nonce", nonce)), and writes it to the Content-Security-Policy response header.
  2. web/controller/dist.go reads that same nonce from context (c.GetString("csp_nonce")) and injects <script nonce="NONCE">window.X_UI_BASE_PATH="…";</script> into the HTML just before </head>.

Because both values come from the same request-scoped context, they must always match — unless something in the environment is modifying the response after it leaves the Go process.

One inconsistency in your report

Looking at the source of dist.go (line 81): window.X_UI_CUR_VER and window.X_UI_DB_TYPE are only injected for index.html (the panel SPA), not for login.html. If the blocked script you observed contained all three variables, the page that was actually blank is the post-login panel (index.html), not the sign-in page — even if the title said "Sign in" (which could be left over from a previous navigation or a React auth redirect that never completed because the script was blocked).

Why does a blocked script cause a blank page?

vite.config.ts uses experimental.renderBuiltUrl to resolve dynamic chunk imports at runtime:

runtime: `((window.X_UI_BASE_PATH||'/')+${JSON.stringify(filename)})`

If window.X_UI_BASE_PATH is not set (because the inline script was blocked) and you use a non-default webBasePath, all lazy-loaded vendor chunks (vendor-react, vendor-antd, etc.) resolve to /assets/… instead of /your-base/assets/…, fail to load, and React never mounts — leaving the page blank.

Debugging steps

1. Hard-refresh first.
Press Ctrl + Shift + R (Firefox) to bypass the browser cache and force a full reload. If this fixes it, the root cause is a stale cached HTML page that was served without a nonce= attribute on the inline script.

2. Check whether the nonce is actually in the served HTML.
Open the page, right-click → View Page Source (not DevTools Elements, which shows the parsed DOM). Search for <script nonce=. You should see something like:

<script nonce="aBcDeFgH1234">window.X_UI_BASE_PATH="/your-path/";</script>

Then check the Content-Security-Policy response header for the same request (DevTools → Network tab → the HTML document → Response Headers). The value after 'nonce- in the CSP must exactly match the nonce= attribute in the script tag.

3. If the nonce is missing or mismatched, please share:

  • The exact Content-Security-Policy header value from the Network tab.
  • The relevant <script …> line from View Page Source.
  • What version you were running before upgrading to 3.2.8.
  • Whether there is any software on the same server that could touch HTTP responses (HAProxy, Nginx, CDN, Cloudflare, etc.) — even if 3x-ui itself has no reverse proxy configured, the hosting environment sometimes does.

The fallback meta tags (<meta name="base-path"> and <meta name="csrf-token">) are always injected by dist.go even when the inline script is blocked, so those values survive. The missing piece for a custom webBasePath is specifically window.X_UI_BASE_PATH, which the chunk-loading runtime depends on.

<!-- gh-comment-id:4631361089 --> @github-actions[bot] commented on GitHub (Jun 5, 2026): Thanks for the detailed report. Here's what the code does and how to narrow this down. ## How the CSP nonce works The CSP security headers (including the `script-src 'nonce-…'` directive) were introduced in v3.0.2 via a security hardening commit. The mechanism works as follows, all within a single HTTP request: 1. `web/middleware/security.go` generates a fresh random nonce with `crypto/rand`, stores it in the Gin context (`c.Set("csp_nonce", nonce)`), and writes it to the `Content-Security-Policy` response header. 2. `web/controller/dist.go` reads that same nonce from context (`c.GetString("csp_nonce")`) and injects `<script nonce="NONCE">window.X_UI_BASE_PATH="…";</script>` into the HTML just before `</head>`. Because both values come from the same request-scoped context, they must always match — unless something in the environment is modifying the response after it leaves the Go process. ## One inconsistency in your report Looking at the source of `dist.go` (line 81): `window.X_UI_CUR_VER` and `window.X_UI_DB_TYPE` are only injected for `index.html` (the panel SPA), **not** for `login.html`. If the blocked script you observed contained all three variables, the page that was actually blank is the post-login panel (`index.html`), not the sign-in page — even if the title said "Sign in" (which could be left over from a previous navigation or a React auth redirect that never completed because the script was blocked). ## Why does a blocked script cause a blank page? `vite.config.ts` uses `experimental.renderBuiltUrl` to resolve dynamic chunk imports at runtime: ```js runtime: `((window.X_UI_BASE_PATH||'/')+${JSON.stringify(filename)})` ``` If `window.X_UI_BASE_PATH` is not set (because the inline script was blocked) and you use a non-default `webBasePath`, all lazy-loaded vendor chunks (`vendor-react`, `vendor-antd`, etc.) resolve to `/assets/…` instead of `/your-base/assets/…`, fail to load, and React never mounts — leaving the page blank. ## Debugging steps **1. Hard-refresh first.** Press **Ctrl + Shift + R** (Firefox) to bypass the browser cache and force a full reload. If this fixes it, the root cause is a stale cached HTML page that was served without a `nonce=` attribute on the inline script. **2. Check whether the nonce is actually in the served HTML.** Open the page, right-click → *View Page Source* (not DevTools Elements, which shows the parsed DOM). Search for `<script nonce=`. You should see something like: ```html <script nonce="aBcDeFgH1234">window.X_UI_BASE_PATH="/your-path/";</script> ``` Then check the `Content-Security-Policy` response header for the same request (DevTools → Network tab → the HTML document → Response Headers). The value after `'nonce-` in the CSP must exactly match the `nonce=` attribute in the script tag. **3. If the nonce is missing or mismatched**, please share: - The exact `Content-Security-Policy` header value from the Network tab. - The relevant `<script …>` line from View Page Source. - What version you were running **before** upgrading to 3.2.8. - Whether there is any software on the same server that could touch HTTP responses (HAProxy, Nginx, CDN, Cloudflare, etc.) — even if 3x-ui itself has no reverse proxy configured, the hosting environment sometimes does. The fallback meta tags (`<meta name="base-path">` and `<meta name="csrf-token">`) are always injected by `dist.go` even when the inline script is blocked, so those values survive. The missing piece for a custom `webBasePath` is specifically `window.X_UI_BASE_PATH`, which the chunk-loading runtime depends on.
Author
Owner

@ubelian commented on GitHub (Jun 5, 2026):

I checked it directly against the local 3x-ui HTTPS listener, without Nginx, HAProxy, CDN or any reverse proxy:

curl -sk https://127.0.0.1:18143/<webBasePath>/ | grep -A2 -B2 X_UI_BASE_PATH
curl -skD - https://127.0.0.1:18143/<webBasePath>/ -o /dev/null | grep -i content-security-policy

Result:

HTML contains:
<script nonce="8YQnzxXxbTvtghVeFncCkg">window.X_UI_BASE_PATH="/<webBasePath>/";</script>

Response header contains:
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-fwYb/pI38OS/VN7jmKL8tg'; ...

So the nonce in the inline script and the nonce in the CSP header are different even when requesting https://127.0.0.1:18143/... directly from the 3x-ui process.

There is no reverse proxy/CDN involved in this test.

<!-- gh-comment-id:4631421637 --> @ubelian commented on GitHub (Jun 5, 2026): I checked it directly against the local 3x-ui HTTPS listener, without Nginx, HAProxy, CDN or any reverse proxy: ```bash curl -sk https://127.0.0.1:18143/<webBasePath>/ | grep -A2 -B2 X_UI_BASE_PATH curl -skD - https://127.0.0.1:18143/<webBasePath>/ -o /dev/null | grep -i content-security-policy ``` **Result:** HTML contains: `<script nonce="8YQnzxXxbTvtghVeFncCkg">window.X_UI_BASE_PATH="/<webBasePath>/";</script>` Response header contains: `Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-fwYb/pI38OS/VN7jmKL8tg'; ...` So the nonce in the inline script and the nonce in the CSP header are different even when requesting https://127.0.0.1:18143/... directly from the 3x-ui process. There is no reverse proxy/CDN involved in this test.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3484
No description provided.