NATS Server may fail to authorize certain Jetstream admin APIs
AdvisoryThe management of JetStream assets happens with messages in the `$JS.` subject namespace in the system account; this is partially exposed into regular accounts to allow account holders to manage their assets.Some of the JS API requests were missing access controls, allowing any user with JS management permissions in any account to perform certain administrative actions on any JS asset in any other account. At least one of the unprotected APIs allows for data destruction. None of the affected APIs allow disclosing stream contents.Affected versionsNATS Server:Version 2 from v2.2.0 onwards, prior to v2.11.1 or v2.10.27Original Report(Lightly edited to confirm some supposition and in the summary to use past tense)Summarynats-server did not include authorization checks on 4 separate admin-level JetStream APIs: account purge, server remove,  account stream move, and  account stream cancel-move.In all cases, APIs are not properly restricted to system-account users. Instead, _any_ authorized user can execute the APIs, including across account boundaries, as long as the current user merely has permission to publish on `$JS.>`.Only the first seems to be of highest severity. All are included in this single report as they seem likely to have the same underlying root cause.Reproduction of the `ACCOUNT.PURGE` case is below. The others are like it.Details & ImpactIssue 1: `$JS.API.ACCOUNT.PURGE.*`Any user may perform an account purge of any other account (including their own).Risk: total destruction of Jetstream configuration and data.Issue 2: `$JS.API.SERVER.REMOVE`Any user may remove servers from Jetstream clusters.Risk: Loss of data redundancy, reduction of service quality.Issue 3: `$JS.API.ACCOUNT.STREAM.MOVE.*.*` and `CANCEL_MOVE`Any user may cause streams to be moved between servers.Risk: loss of control of data provenance, reduced service quality during move, enumeration of account and/or stream names.Similarly for `$JS.API.ACCOUNT.STREAM.CANCEL_MOVE.*.*`MitigationsIt appears that users without permission to publish on `$JS.API.ACCOUNT.>` or `$JS.API.SERVER.>` are unable to execute the above APIs.Unfortunately, in many configurations, an 'admin' user for a single account will be given permissions for `$JS.>` (or simply `>`), which allows the improper access to the system APIs above.Scope of impactIssues 1 and 3 both cross boundaries between accounts, violating promised account isolation. All 3 allow system level access to non-system account users.While I cannot speak to what authz configurations are actually found in the wild, per the discussion in Mitigations above, it seems likely that at least some configurations are vulnerable.Additional notesIt appears that `$JS.API.META.LEADER.STEPDOWN` does properly restrict to system account users. As such, this may be a pattern for how to properly authorize these other APIs.PoCEnvironmentTested with:
nats-server 2.10.26 (installed via homebrew)
nats cli 0.1.6 (installed via homebrew)
macOS 13.7.4Reproduction steps