[PR #5613] [MERGED] fix(nodes): make node API tokens write-only #5929

Closed
opened 2026-11-02 04:05:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5613
Author: @n0ctal
Created: 6/27/2026
Status: ✅ Merged
Merged: 7/23/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-c-writeonly-node-token


📝 Commits (3)

  • a9ae7bd fix(nodes): make node API tokens write-only
  • 7a27a57 Merge branch 'main' into upstream-c-writeonly-node-token
  • e33b17d fix(nodes): keep token optional on edit for write-only API tokens

📊 Changes

29 files changed (+1716 additions, -88 deletions)

View changed files

📝 frontend/public/openapi.json (+428 -29)
📝 frontend/src/generated/examples.ts (+65 -1)
📝 frontend/src/generated/schemas.ts (+302 -5)
📝 frontend/src/generated/types.ts (+63 -1)
📝 frontend/src/generated/zod.ts (+65 -1)
📝 frontend/src/pages/api-docs/endpoints.ts (+7 -5)
📝 frontend/src/pages/nodes/NodeFormModal.tsx (+15 -5)
📝 frontend/src/schemas/node.ts (+3 -1)
📝 internal/database/model/model.go (+1 -1)
📝 internal/web/controller/node.go (+42 -39)
➕ internal/web/controller/node_credentials_writeonly_test.go (+192 -0)
📝 internal/web/service/node.go (+123 -0)
➕ internal/web/service/node_contract.go (+186 -0)
➕ internal/web/service/node_credentials_writeonly_test.go (+201 -0)
📝 internal/web/service/node_tree.go (+8 -0)
📝 internal/web/translation/ar-EG.json (+1 -0)
📝 internal/web/translation/en-US.json (+1 -0)
📝 internal/web/translation/es-ES.json (+1 -0)
📝 internal/web/translation/fa-IR.json (+1 -0)
📝 internal/web/translation/id-ID.json (+1 -0)

...and 9 more files

📄 Description

Summary

  • Make node API tokens write-only in node API responses.
  • Preserve backwards-compatible update behavior: omitted or blank apiToken keeps the stored token.
  • Add explicit clearApiToken for intentional token removal.
  • Regenerate API schemas/types and the OpenAPI document for the new NodeView / NodeMutationRequest contract.

Why

Returning a node's API token in list/get/add responses leaks a credential that can control the remote node API. The previous draft fixed the leak but made blank apiToken an error on update, which broke the existing UI pattern where an empty token field is submitted for an existing node.

This revision keeps the security invariant while preserving the old edit/test flow.

Scope

  • model.Node.ApiToken is excluded from JSON/form serialization.
  • Node read endpoints return NodeView, which exposes only hasApiToken.
  • Node write/probe endpoints accept NodeMutationRequest.
  • On update, apiToken omitted or blank means keep the stored token.
  • clearApiToken=true explicitly clears the token.
  • Enabled non-mTLS nodes still require a stored or supplied token.
  • OpenAPI/generated frontend types now include NodeView, NodeMutationRequest, hasApiToken, and clearApiToken.

Validation

  • go test ./internal/web/service ./internal/web/controller -run 'NodeCredential|NodeController.*Token|NodeUpdateRequiresToken|NodeCredentialsNeverMarshal|NodeViewExposesOnlyCredentialPresence|CheckAPIAuth' -count=1 -v
  • go vet ./internal/web/service ./internal/web/controller ./tools/openapigen
  • go build ./...
  • npm run gen
  • npm run build
  • npm run typecheck
  • git diff --check

make gen / make verify are not present in this upstream tree; the equivalent project scripts above were used.

Risk

Low. Existing API clients that send an empty token while editing a node continue to work and keep the stored token. Clients that intentionally need to clear the token must use clearApiToken=true; clearing is rejected for enabled non-mTLS nodes unless another authentication method is configured.

The response shape changes from apiToken to hasApiToken. That is the intended security boundary: credentials are accepted only on write and are never returned on read.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5613 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 6/27/2026 **Status:** ✅ Merged **Merged:** 7/23/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-c-writeonly-node-token` --- ### 📝 Commits (3) - [`a9ae7bd`](https://github.com/MHSanaei/3x-ui/commit/a9ae7bdd2c5bb4820bf26ee0a6b5239bdb3c1fa5) fix(nodes): make node API tokens write-only - [`7a27a57`](https://github.com/MHSanaei/3x-ui/commit/7a27a573e1370f0c29965cbd53acc43deda80334) Merge branch 'main' into upstream-c-writeonly-node-token - [`e33b17d`](https://github.com/MHSanaei/3x-ui/commit/e33b17de60e4e2f9e7e1cd1518b9ce9cfa0ab736) fix(nodes): keep token optional on edit for write-only API tokens ### 📊 Changes **29 files changed** (+1716 additions, -88 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+428 -29) 📝 `frontend/src/generated/examples.ts` (+65 -1) 📝 `frontend/src/generated/schemas.ts` (+302 -5) 📝 `frontend/src/generated/types.ts` (+63 -1) 📝 `frontend/src/generated/zod.ts` (+65 -1) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+7 -5) 📝 `frontend/src/pages/nodes/NodeFormModal.tsx` (+15 -5) 📝 `frontend/src/schemas/node.ts` (+3 -1) 📝 `internal/database/model/model.go` (+1 -1) 📝 `internal/web/controller/node.go` (+42 -39) ➕ `internal/web/controller/node_credentials_writeonly_test.go` (+192 -0) 📝 `internal/web/service/node.go` (+123 -0) ➕ `internal/web/service/node_contract.go` (+186 -0) ➕ `internal/web/service/node_credentials_writeonly_test.go` (+201 -0) 📝 `internal/web/service/node_tree.go` (+8 -0) 📝 `internal/web/translation/ar-EG.json` (+1 -0) 📝 `internal/web/translation/en-US.json` (+1 -0) 📝 `internal/web/translation/es-ES.json` (+1 -0) 📝 `internal/web/translation/fa-IR.json` (+1 -0) 📝 `internal/web/translation/id-ID.json` (+1 -0) _...and 9 more files_ </details> ### 📄 Description ## Summary - Make node API tokens write-only in node API responses. - Preserve backwards-compatible update behavior: omitted or blank `apiToken` keeps the stored token. - Add explicit `clearApiToken` for intentional token removal. - Regenerate API schemas/types and the OpenAPI document for the new `NodeView` / `NodeMutationRequest` contract. ## Why Returning a node's API token in list/get/add responses leaks a credential that can control the remote node API. The previous draft fixed the leak but made blank `apiToken` an error on update, which broke the existing UI pattern where an empty token field is submitted for an existing node. This revision keeps the security invariant while preserving the old edit/test flow. ## Scope - `model.Node.ApiToken` is excluded from JSON/form serialization. - Node read endpoints return `NodeView`, which exposes only `hasApiToken`. - Node write/probe endpoints accept `NodeMutationRequest`. - On update, `apiToken` omitted or blank means keep the stored token. - `clearApiToken=true` explicitly clears the token. - Enabled non-mTLS nodes still require a stored or supplied token. - OpenAPI/generated frontend types now include `NodeView`, `NodeMutationRequest`, `hasApiToken`, and `clearApiToken`. ## Validation - `go test ./internal/web/service ./internal/web/controller -run 'NodeCredential|NodeController.*Token|NodeUpdateRequiresToken|NodeCredentialsNeverMarshal|NodeViewExposesOnlyCredentialPresence|CheckAPIAuth' -count=1 -v` - `go vet ./internal/web/service ./internal/web/controller ./tools/openapigen` - `go build ./...` - `npm run gen` - `npm run build` - `npm run typecheck` - `git diff --check` `make gen` / `make verify` are not present in this upstream tree; the equivalent project scripts above were used. ## Risk Low. Existing API clients that send an empty token while editing a node continue to work and keep the stored token. Clients that intentionally need to clear the token must use `clearApiToken=true`; clearing is rejected for enabled non-mTLS nodes unless another authentication method is configured. The response shape changes from `apiToken` to `hasApiToken`. That is the intended security boundary: credentials are accepted only on write and are never returned on read. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:06 +07:00
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#5929
No description provided.