Marc Schier e3d322cbf5 Fix three high-severity audit findings in new 2.0 pub sub/GDS code (#3954)
# Description

Fixes three high-severity, remotely-relevant security weaknesses
identified by a full-codebase security audit. Each fix is minimal and
surgical, and ships with regression tests.

### 1. PubSub inbound message-security fail-open for non-UADP (JSON)
frames

`PubSubConnection` nested the inbound signature/encryption/replay
enforcement **inside** the `UadpDecoder.TryReadOuterPrefix(...)` branch.
Because that check returns `false` for a JSON frame, a reader configured
for `Sign`/`SignAndEncrypt` over a JSON transport silently accepted
attacker-forged, unauthenticated frames, delivering forged
DataSet/MetaData messages to application sinks. The send path already
fail-*closes* the identical case.

**Fix:** drop any non-UADP frame fail-closed on a secured reader before
decode (`else if (RequiresInboundSecurity)`), mirroring the send-side
refusal.

### 2. Client schema-import SSRF / NetNTLM credential leak

When loading complex types, the client falls back to the server's type
dictionary and resolves each `Import`/`SchemaLocation` against the local
file system with no sanitization. A malicious server could supply a UNC
path (e.g. `\\attacker\share\x`), triggering an outbound SMB/NetNTLM
handshake (hash theft / SSRF) or arbitrary local file read. This
bypassed the existing XXE hardening because imports are followed by
manual file-system code, not the XML resolver.

**Fix:** added a deny-all `NullFileSystem` and wired it into the
in-memory/import-table schema validator constructors, so
network-supplied dictionaries never touch the local file system. The XML
loader now prefers the in-memory import table before any (untrusted)
location, so legitimate in-memory resolution is unchanged.

### 3. GDS AuthorizationService JWT impersonation / privilege escalation

`FinishRequestToken` derived the JWT subject from the
**unauthenticated** client-supplied `userIdentityToken` (never verifying
`userTokenSignature`) and embedded the client's `requestedRoles`
verbatim. Any caller able to open an encrypted channel — even anonymous
— could obtain a GDS-signed token asserting `sub=admin`,
`roles=[SecurityAdmin, ...]`, impersonating any principal to resource
servers that trust GDS-issued JWTs.

**Fix:**
- The token subject is now bound to the identity that was
**authenticated on the session** when the request was started; the
client token is no longer trusted for the subject.
- Requested roles are gated by a new **fail-closed**
`AuthorizationServiceOptions.AuthorizeRoles` hook. With no callback
configured, **no roles** are granted; the callback can only ever narrow
the requested set. This removes privilege escalation via arbitrary role
requests.
- The obsolete single-call `RequestAccessToken` path no longer trusts
the client-supplied token: it issues an unprivileged
**anonymous**-subject token with no roles. Use
`StartRequestToken`/`FinishRequestToken` for authenticated identity
binding.

## Related Issues

No public issue is linked — these findings were identified by an
internal security audit and fixed directly. Maintainers may open
tracking issues if desired.

## Verification

- All affected projects build with **0 warnings / 0 errors** (net10.0).
- Regression tests added and passing:
- PubSub: `SecuredReaderRejectsNonUadpJsonFrameAsync` (+ existing
receive-security suite, 6/6).
- Schema/SSRF: `NullFileSystemTests` (6/6),
`ImportTableValidatorDoesNotResolveServerSuppliedFilesystemLocation`
(BSD, 3/3), source-gen schema validation (6 passed), full ComplexTypes
client-load suite (2214/2214).
- GDS: `FinishDoesNotGrantRequestedRolesWithoutAuthorization`,
`FinishBindsSubjectToAuthenticatedIdentityNotRequestToken`, plus
`LegacyRequestAccessTokenIssuesAnonymousUnprivilegedToken` and
`AuthorizeRoles` intersection/empty edge cases (AuthorizationService
unit 15/15, RefreshToken integration 3/3).

_Review feedback from the automated reviewer has been addressed
(NullFileSystem singleton constructor + header year, PubSub drop logged
at Debug to avoid log amplification, and the obsolete
`RequestAccessToken` path simplified to a uniform anonymous subject);
all review threads resolved._
2026-07-06 08:48:07 +02:00
2020-05-15 19:41:55 +02:00
2021-07-26 10:06:51 +03:00

OPC UA .NET Standard Stack

Release NuGet Downloads Build Tests Coverage

🆕 This is version 2.0 of the OPC UA .NET Standard Stack (current master).

Looking for the supported 1.x release? It lives on the master378 branch (last release: 1.5.378). All new feature work happens here on master; master378 continues to receive security and critical-bug fixes for the 1.x line.

The official OPC Foundation reference implementation of OPC UA for .NET — a certified, cross-platform stack with client, server, PubSub, GDS, complex types, and source-generated tooling. Used in production across industrial control, manufacturing, energy, and IoT systems.

📦 What it is

  • A full-stack OPC UA implementation — Core / Client / Server / PubSub / GDS / LDS / Complex Types / Device Integration libraries built on .NET, with UA-TCP and HTTPS transports.
  • Cross-platform — runs on .NET 10, .NET 9, .NET 8 (LTS), .NET Framework 4.8, and .NET Standard 2.1; ships Native-AOT-friendly assemblies.
  • Certified for compliance — the reference server has been certified through an OPC Foundation Certification Test Lab and is continuously verified against the latest Compliance Test Tool (CTT).
  • Companion-spec coverage — Part 9 (Alarms & Conditions), Part 11 (Historical Access), Part 13 (Aggregates), Part 16 (State Machines), Part 17 (Alias Names), Part 18 (Role Management), Part 20 (File Transfer), Part 100 (Device Integration), OPC 10100-1 (WoT Connectivity).
  • Modern developer surface — first-class Microsoft.Extensions.DependencyInjection hosting (services.AddOpcUa()), fluent server + client builders, source-generated NodeManagers and DataTypes, and an MCP server so LLMs / Copilot can drive an OPC UA client.

For the full feature breakdown see OPC UA Profiles and Facets and the What's New in 2.0 tour.

🚀 Getting started

You need the .NET 10 SDK to build the repo. From the repository root:

dotnet restore UA.slnx
dotnet build UA.slnx

For the supported target frameworks and platform notes see Platform Support. The official NuGet packages are published to nuget.org under the OPCFoundation.NetStandard prefix — the meta package OPCFoundation.NetStandard.Opc.Ua pulls in everything, or pick the split OPCFoundation.NetStandard.Opc.Ua.Core / .Client / .Server / .Bindings.Https packages directly. Preview builds for every successful master build are available in the Azure DevOps opcua-preview feed.

Sample applications

Each sample has its own README.md with build and run instructions.

Reference applications

  • Console Reference Server — the certified reference server (with Quickstarts, CTT, and Mono configs). Also ships as a Docker container.
  • Console Reference Client — cross-platform reference client demonstrating sessions, subscriptions, browsing, and method calls.
  • Console LDS Server — a standalone Local Discovery Server built on Opc.Ua.Lds.Server.
  • MCP Server — Model Context Protocol server that exposes OPC UA client operations as MCP tools, so an LLM / Copilot can browse, read, write, subscribe, and call methods on any OPC UA server.

PubSub samples

  • Console Reference PubSub Client — one executable with publisher, subscriber, and external (external-server adapter) modes across the supported transport profiles.

Minimal / Device-Integration samples

More sample projects are maintained in the companion OPC UA .NET Samples repository.

🔧 Migrating from 1.5.378 to 2.0

The 2.0 release introduces breaking API changes, and comes with a full prescriptive migration guide that links to per-area documentation covering telemetry, packages, source generation, types, encoders, node states, identity, certificates, configuration, sessions / subscriptions, alarms / model change, and TimeProvider.

Most of the mechanical migration work is automated:

  • OPCFoundation.NetStandard.Opc.Ua.MigrationAnalyzer NuGet — install it in your project to get analyzer warnings (UA0001–UA0022)
    • one-click code fixes for the patterns in the guide. Setup steps are in the package's NugetREADME.md.
  • Migration agent skill — the opcua-v20-migration skill walks Copilot / Claude / any coding agent through installing the NuGet, running dotnet format analyzers to apply auto-fixes, and handling the small residual manual patterns. The skill knows which sub-doc to load for each symptom so it stays context-efficient.

If you are still on 1.x and not ready to upgrade, stay on the master378 branch — it continues to receive security and critical-bug fixes.

🤝 Contributing and license

Community contributions are welcome. Fork the repository, make your changes on a branch, and open a pull request; see CONTRIBUTING.md for the contribution workflow.

Contributors must sign the OPC Foundation Contributor License Agreement (CLA). The CLA "I AGREE" gate is presented automatically on your first PR.

The project is licensed under the OPC Foundation MIT License. Report security vulnerabilities via the process documented in SECURITY.md.

📚 Further reading

S
Description
OPC Unified Architecture .NET Standard
Readme
296 MiB
Languages
C# 99.4%
PowerShell 0.2%