mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6188] [MERGED] fix(nodes): validate every certificate in the node mTLS trust bundle #6150
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#6150
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/6188
Author: @n0ctal
Created: 8/8/2026
Status: ✅ Merged
Merged: 8/15/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-strict-mtls-ca-bundle📝 Commits (2)
09ec123fix(nodes): validate every certificate in the node mTLS trust bundleac02a6cfix(mtls): reject malformed certificate bundle layout📊 Changes
3 files changed (+116 additions, -14 deletions)
View changed files
📝
internal/web/service/node_mtls.go(+4 -12)📝
internal/web/service/setting_mtls.go(+38 -2)➕
internal/web/service/setting_mtls_bundle_test.go(+74 -0)📄 Description
Summary
Parse and validate every certificate in the node mTLS trust bundle instead of only the first one, and reject the bundle if any block is malformed.
Why
Two places accept the
nodeMtlsClientCAPemtrust bundle, and both are satisfied by a bundle that is only partly valid:NodeMtlsClientCAPoolbuilds the listener'sClientCAswithx509.CertPool.AppendCertsFromPEM, which returnstrueas soon as one certificate parses. Later entries that are damaged or truncated are skipped, and the pool is returned as if nothing were wrong.SetNodeMtlsTrustCAvalidates the value before storing it, butpem.Decodereturns only the first block and the remainder is discarded, so only the first certificate is ever checked.Together these mean a bundle can be stored, reported as valid, and then produce a trust pool that is missing certificates nobody was told about.
This matters most during a CA rotation, which is the one time a bundle legitimately holds two certificates. The operator stores
old CA + new CA, both calls report success, and the new CA is silently absent from the pool. Every node then rejects the panel's new client certificate at once — and the failure surfaces only when the panel next needs the node API, because data-plane traffic does not go through it.Scope
parseCertificateBundlePEMwalks the whole bundle, requiring every block to be a parseableCERTIFICATE, and rejects an empty bundle, a non-certificate block, and trailing non-PEM bytes.NodeMtlsClientCAPoolbuilds the pool from the parsed certificates withAddCert, so a partially valid bundle is an error rather than a quietly reduced pool.SetNodeMtlsTrustCAvalidates through the same helper, so what is accepted on write is exactly what will load on read.Validation
go build ./...,go vet,golangci-lint runclean onmainatece16559.go test ./internal/web/service/green.AppendCertsFromPEMimplementation it fails, reporting a pool built from one certificate while the second was dropped; it passes with this change.Risk
Low. The change is strictly a tightening of validation on a value that is expected to contain only certificates. Existing single-certificate configurations are unaffected.
One behaviour worth calling out: a stored bundle with trailing text after the last certificate used to load, and now will not. Operators who paste output from tools that append human-readable text would see the trust pool fail to build. That failure is currently non-fatal —
web.gologs a warning and starts the listener without mTLS, falling back to bearer-token auth for the node API — so a bad bundle degrades the node API from two factors to one rather than stopping the panel. I think that fallback deserves to fail closed instead, but it predates this change and I did not want to fold an unrelated behaviour change into a validation fix. Happy to send it separately if you agree.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.