mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #5613] [MERGED] fix(nodes): make node API tokens write-only #5929
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#5929
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
a9ae7bdfix(nodes): make node API tokens write-only7a27a57Merge branch 'main' into upstream-c-writeonly-node-tokene33b17dfix(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
apiTokenkeeps the stored token.clearApiTokenfor intentional token removal.NodeView/NodeMutationRequestcontract.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
apiTokenan 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.ApiTokenis excluded from JSON/form serialization.NodeView, which exposes onlyhasApiToken.NodeMutationRequest.apiTokenomitted or blank means keep the stored token.clearApiToken=trueexplicitly clears the token.NodeView,NodeMutationRequest,hasApiToken, andclearApiToken.Validation
go test ./internal/web/service ./internal/web/controller -run 'NodeCredential|NodeController.*Token|NodeUpdateRequiresToken|NodeCredentialsNeverMarshal|NodeViewExposesOnlyCredentialPresence|CheckAPIAuth' -count=1 -vgo vet ./internal/web/service ./internal/web/controller ./tools/openapigengo build ./...npm run gennpm run buildnpm run typecheckgit diff --checkmake gen/make verifyare 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
apiTokentohasApiToken. 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.