tls: document Prefer mode plaintext behavior#1094
Conversation
The TlsMode.Prefer XML docs said "if the Server supports TLS, then use it" without mentioning that "supports TLS" comes from an unauthenticated plaintext INFO message that a MITM can forge. Add remarks to Prefer, Auto, and NatsTlsOpts.Mode explaining the opportunistic nature and pointing users to tls:// or Require when they actually need TLS. Add a test that proves it: a fake TCP server strips the TLS flags from INFO and the client happily sends CONNECT with credentials in plaintext. This is by-design (every NATS client works this way), but now it's documented and tested rather than implicit.
|
Claude finished @mtmk's task in 3m 22s —— View job PR Review: tls: document MITM downgrade risk in Prefer mode
SummaryGood PR. The documentation accurately describes the MITM downgrade risk, uses proper Documentation (
|
Drop MITM/attacker framing from XML docs and test comments. Prefer mode is simply opportunistic TLS; the connection may stay plaintext when the server doesn't advertise TLS. Rename test class and file to TlsPreferTest.
Document that Prefer/Auto mode attempts TLS upgrade when the server advertises tls_available, which differs from most other NATS clients. Add guidance to use TlsMode.Disable behind a TLS-terminating proxy. Add real nats-server tests for the tls_available scenario and a Go client cross-check via GoHarness.
philpennock
left a comment
There was a problem hiding this comment.
Did not review tests.
If it is not too late to rename Implicit, it would be good to do so, as "implicit" might be taken as "ambiently available without our seeing it", via things like stunnel or equivalent cryptographic privacy (tailscale etc). I'd name it OnConnect and make clear that it is a stronger form of Require. I'd also mention explicitly below the table that only Require and (OnConnect or Implicit) provide the full protection which TLS can offer.
Looks good as is, the feedback above is non-blocking.
@philpennock thanks for the review! good point. We can deprecate Will also add the note about full TLS protection. |
|
I retract my previous suggestion to avoid "Implicit". That's the RFC 8314 terminology so we should stick with it for consistency even if it is a little unfortunate. |
Add remarks to TlsMode enum, Mode property, and security docs clarifying that other modes may fall back to plaintext.
The GoHarness test downloads Go 1.25.x at runtime when the runner has an older version. Pin go-version to stable so the runner already has the latest Go, and bump the test timeout from 60s to 180s for slow CI environments.
|
test failures for 'Check_JetStream_cluster_related_fields' are not related to this PR. We can investigate after merge to main. |
Documents TLS Prefer/Auto mode behavior and adds guidance for TLS-terminating proxy setups (nats-io/nats-server#7927).
Unlike most other NATS clients (Go, Rust, Java, Python), the .NET client attempts a TLS upgrade when the server advertises
tls_availablewithouttls_required. This can cause connection failures behind a TLS-terminating proxy. The workaround isTlsMode.Disable.We are not changing the default behavior to match other clients because existing configurations may rely on the automatic TLS upgrade. Switching to plaintext silently would be a security regression for those users.
tls {}+allow_non_tls