4276 Commits
Author SHA1 Message Date
Nikos Mavrogiannopoulos 2315b91894 ocserv.8.md: corrected SYNOPSIS
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-29 10:42:35 +02:00
Nikos Mavrogiannopoulos 1002c6fce7 README.md: document that this is only about Intune VPN
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-29 08:25:01 +02:00
Nikos Mavrogiannopoulos 77e06aec8a sec-mod, worker: harden TLS resumption cache against empty session data
A cached resume entry can end up with zero-length session_data, which is
not valid resumption data.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-28 08:07:07 +02:00
Nikos Mavrogiannopoulos 9e71c1b8b6 worker: use TLS 1.3 transparent rekey on TLS 1.3 CSTP sessions
TLS 1.3 has no renegotiation and provides transparent rekeys but this
was not used by the server. Instead rekey-method=ssl was silently
downgraded to new-tunnel, causing a full tunnel/TUN-device rebuild (and
a brief data-path interruption) on every rekey whenever a client
negotiated TLS 1.3.

This commit simplifies that handling by taking advantage of TLS 1.3's own
rekey mechanism instead: the server now performs the "ssl" rekey on
TLS 1.3 sessions via the standard TLS 1.3 KeyUpdate message.

TLS <= 1.2 rekey behavior (client-driven rehandshake, gated on RFC
5746 safe renegotiation) is unchanged.

Resolves: #745

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-28 08:07:07 +02:00
Nikos Mavrogiannopoulos 76987ccb82 tlslib, worker: remove dead code orphaned by the listen-clear-file removal
Commit 5cf457b4 ("Removed the listen-clear-file config option", Dec
2020) deleted the only code path that could ever construct a
SOCK_TYPE_UNIX worker connection, but left every branch that handled
it in place. Since then ws->session has been unconditionally non-NULL
and ws->conn_type unconditionally not SOCK_TYPE_UNIX for every worker,
making all of the following unreachable:

 - tlslib.c: recv_remaining(), _cstp_recv_packet() (the non-TLS CSTP
   reassembly path hardened in the previous commit), and
   tls_has_session_cert() (zero callers) deleted outright; cstp_cork/
   cstp_uncork/cstp_send/cstp_recv_packet/cstp_recv/cstp_close/
   cstp_fatal_close collapsed to their TLS-only body.
 - worker-http.c, worker-auth.c, worker-vpn.c, main.c: dead
   ws->session == NULL / ws->conn_type == SOCK_TYPE_UNIX branches
   removed or simplified to their live half.
 - worker-proxyproto.c: parse_ssl_tlvs() and its TLV structs/macros
   removed. This proxy-protocol SSL-CN extraction was itself only
   ever invoked from the same dead SOCK_TYPE_UNIX branch, so it has
   been as unreachable as the rest since 2020 despite a recent,
   otherwise-correct bug fix.
 - tests/cstp-recv.c deleted (exercised only the removed reassembly
   path); tests/proxyproto-v2.c trimmed to the still-live IPv6
   address-parsing regression test.
 - doc/sample.config: dropped the stale "TCP or UNIX socket" wording
   for listen-proxy-proto left over from the same 2020 removal; only
   a TCP socket is ever listened on for the proxy protocol now.

Narrows the worker's attack surface to the code paths a client can
actually reach, and removes a source of wasted maintenance effort.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-28 08:00:06 +02:00
Nikos Mavrogiannopoulos 879f723953 tlslib: harden recv_remaining() against truncated CSTP reads
recv_remaining() is used only on the non-TLS CSTP path (a UNIX socket
proxying plaintext CSTP in front of ocserv). On a recv() failure or
peer close mid-read, it discarded the error and returned whatever
partial byte count it had accumulated so far. Since every caller only
checks "ret <= 0" and otherwise trusts the count as a complete read,
a truncated body could come back as a positive, non-zero total that
looked like success: _cstp_recv_packet() would then report the full
8+pktlen size to its caller with only part of the buffer actually
populated from the network, feeding stale/uninitialized bytes into
parse_cstp_data() as if they were received client data.

Make the contract unambiguous: recv_remaining() now returns either
exactly the requested byte count or a negative error - never a
partial positive count a caller could mistake for success.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-28 08:00:06 +02:00
Nikos Mavrogiannopoulos d79eda6013 ip-util: reject routes with characters outside address/prefix syntax
ip_route_sanity_check() was a format normalizer, not a validator: any
dot-free route (all IPv6, or arbitrary text) returned success
unexamined, and a dotted-netmask IPv4 route passed through unchanged.
Since route_adddel() substitutes the validated route into
route-add-cmd/route-del-cmd and executes it via `/bin/sh -c` as root,
a route string carrying shell metacharacters that survived this check
was a root command-injection vector.

Rewrite the check to fully parse the route as an IPv4 or IPv6 address
plus prefix, or the literal keyword "default" (the documented
all-traffic-through-VPN shortcut, checked separately by config.c after
this function runs), and reject anything left over. Numeric IPv4
prefixes are still normalized to a dotted netmask as before.

Adds REQ-MAIN-SEC-008 and tests/route-sanity-check.c, confirmed
against real config/test usage (including "route = default") so the
stricter validation doesn't regress documented syntax.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-28 08:00:06 +02:00
Nikos Mavrogiannopoulos 5a9cddf606 main: validate AUTH_COOKIE_REQ cookie length before use
main read cookie.data[0] (to select sec_mod_instance_index) before
validating the cookie's length. A worker sending an empty cookie
unpacks with cookie.data == NULL (protobuf-c "required bytes"
semantics), so the read crashed the root main process, tearing down
every connected client.

Validate cookie.data/len immediately after unpacking, before the
first byte is read. handle_auth_cookie_req()'s own later check
remains as defense-in-depth.

Adds REQ-IPC-018.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-28 08:00:06 +02:00
Nikos Mavrogiannopoulos cdc9a5b5f4 Merge branch 'mr588-worker-seccomp-musl' into 'master'
worker-privs: allow munmap/mremap/madvise for isolated workers

Closes #749

See merge request openconnect/ocserv!588
2026-07-28 05:52:58 +00:00
Alex Protsko b931112cb2 worker-privs: allow munmap/mremap/madvise for isolated workers
Fix worker crashes on musl-based systems when isolate-workers = true by allowing munmap, mremap, and madvise in the worker seccomp filter.

Move seccomp coverage to Alpine CI and use oc_syslog for seccomp trap diagnostics instead of direct write()-based output.

Keep glibc backtrace diagnostics as the default and allow musl builds to select the syscall-only fallback with the assume-glibc Meson option.

Resolves: #749
Signed-off-by: Alex Protsko <fidget2015@yahoo.com>
2026-07-20 16:43:23 +03:00
Nikos Mavrogiannopoulos dde0a16df2 Merge branch 'tmp-coverity' into 'master'
Suppress Coverity Scan defect

See merge request openconnect/ocserv!596
2026-07-16 06:38:24 +00:00
DmitriiandNikos Mavrogiannopoulos df086188d7 radius: send the session ID as Acct-Session-Id in the Access-Request
RFC 2866 (5.5) allows an Access-Request to carry Acct-Session-Id and
requires the same value in the session's Accounting-Requests. Sending it
already at authentication time lets the RADIUS server correlate the two
exchanges by a single per-session key (e.g. for rlm_ippool, so concurrent
sessions of the same user from the same client do not collide on one IP
lease).

Documented as REQ-AUTH-AUTH-025, with a positive check in tests/radius
that the id sent as Acct-Session-Id in the Access-Request matches the
Accounting-Request.

Signed-off-by: Dmitrii <dimmispencer@gmail.com>
Resolves: #751
2026-07-14 21:40:23 +02:00
Dimitri Papadopoulos 20ee8183a3 Fix Coverity Scan defect
CID 498359: Structurally dead code (UNREACHABLE)
unreachable: This code cannot be reached: conn_close(conn);.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-07-12 21:13:27 +02:00
Dimitri Papadopoulos 9172e33f46 Functions return ssize_t
Put the return value into a variable of type ssize_t.

This doesn't really fix an actual bug, as any received packat should fit
into an int. However, it helps analyse the code and address or discard
Coverity Scan defects.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-07-12 21:06:58 +02:00
Nikos Mavrogiannopoulos 6d4f96aa72 doc update
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-12 18:10:23 +02:00
Nikos Mavrogiannopoulos 26e76f9618 doc/requirements: align REQ-IPC-032 and REQ-AUTH-ACCT-002, add REQ-AUTH-ACCT-007
The previous commit dropped stats_st.uptime and the uptime fields of
cli_stats_msg/secm_session_close_msg, computing Acct-Session-Time directly
in sec-mod as now - e->created instead. Update the two requirements that
described the old IPC-carried, summed uptime, and add REQ-AUTH-ACCT-007 to
formally document the Acct-Session-Time definition (wall-clock lifetime of
the logical session, spanning cookie-resumed reconnects, bounded by
session-timeout and cookie-timeout) that was implicit in the fix, citing
tests/radius-reconnect-acct as its acceptance test.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-12 13:56:01 +02:00
Alex ProtskoandNikos Mavrogiannopoulos 5a50aecedc Fix inflated RADIUS Acct-Session-Time across reconnects
A session that reconnects under the same cookie (roaming, DPD, a new-tunnel
rekey) reported an Acct-Session-Time far larger than the real duration. Each
connection segment reported uptime measured from the original session start
(now - e->created, as session_start_time is not reset across reconnects), and
sec-mod summed these per-segment cumulative values, so the reported time grew
~= D*(N+1)/2 with the number of reconnects.

Acct-Session-Time is the wall-clock lifetime of the logical session and is a
pure function of the session creation time, so it does not need to be reported
by the worker, carried through cli_stats_msg / secm_session_close_msg, or
accumulated alongside the byte counters. Drop stats_st.uptime and the uptime
fields of both IPC messages, and compute it in sec-mod as now - e->created:
live for each interim update, and snapshotted at disconnect for the Stop so the
cookie-timeout lingering period is not counted. The byte counters keep their
per-segment report-and-sum handling.

Signed-off-by: Alex Protsko <fidget2015@yahoo.com>
2026-07-12 13:55:59 +02:00
Nikos Mavrogiannopoulos 96aa1f5ae7 tests: add reproducer for inflated RADIUS Acct-Session-Time across reconnects
A session that reconnects several times under the same cookie (roaming,
DPD, a new-tunnel rekey) currently reports an Acct-Session-Time far
larger than its real duration: each reconnected segment reports uptime
measured cumulatively from the original session start, and sec-mod sums
these cumulative per-segment values instead of taking the final one.

Add a test that drives three cookie-resumed segments (simulating
reconnects via SIGKILL, as tests/test-cookie-timeout does, so the
session survives between segments) with idle gaps in between, then
performs a clean final disconnect (SIGTERM), which ocserv reports as an
explicit user disconnect and closes the accounting session immediately.
It checks the Stop record's Acct-Session-Time is close to the real
elapsed wall-clock time rather than the sum of the individual segments'
cumulative uptimes.

This test currently fails against unpatched master.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-12 13:55:55 +02:00
Nikos Mavrogiannopoulos 0f7abd33ca auto-select group when a certificate provides enough information
When a certificate contains a single group there is no need to
request the user to select. Auto-select the group.

Resolves: #692

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-07-12 10:15:11 +02:00
Dimitri Papadopoulos Orfanos 7e8ce7078f Merge branch 'tmp-wget' into 'master'
ci: wget → curl

See merge request openconnect/ocserv!591
2026-07-09 10:16:51 +03:00
Dimitri Papadopoulos 915f819009 ci: wget → curl
Standardise on `curl` instead of using both `wget` and `curl`.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-06-25 13:15:06 +02:00
Nikos Mavrogiannopoulos f3f74de305 tests: do not store environment information
This prevents accidental secret leakage.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-17 06:17:05 +02:00
Nikos Mavrogiannopoulos a53e6d4e25 .gitlab-ci.yml: do not store .tmp files as artifacts
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-17 06:16:37 +02:00
Nikos Mavrogiannopoulos bfe0d9ffd0 requirements: add REQ-CONFIG-SEC-002 for sup-config path-traversal hardening
Documents the intended hardening of get_sup_config() so that
username/groupname (attacker-influenced) can no longer be used to escape
per-user-dir/per-group-dir when looking up supplemental configuration.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-17 06:04:49 +02:00
Nikos Mavrogiannopoulos 5c57855e5c sup-config/file: reject path-traversal in username/groupname
Harden get_sup_config() by treating the username and groupname as
untrusted values.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-17 06:04:49 +02:00
Nikos Mavrogiannopoulos 5c0d4237f1 config: warn about select-group entries that exceed MAX_GROUPNAME_SIZE
Group names are stored in fixed-size (MAX_GROUPNAME_SIZE) worker
buffers, so a configured select-group entry that does not fit can
never be matched against a client-supplied group name. Warn the
administrator about such entries at config-load time, similar to
other configuration sanity checks in check_cfg().

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-17 06:04:49 +02:00
Nikos Mavrogiannopoulos 7fe325de46 ocserv-core-dev agent: validate requirements explicitly
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-17 06:02:56 +02:00
Nikos Mavrogiannopoulos bda207237a requirements: enhanced with general implementation requirements
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-17 05:35:02 +02:00
Nikos Mavrogiannopoulos cfb0e0a2b2 main: improved reporting of errors by main
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-15 22:23:24 +02:00
Nikos Mavrogiannopoulos a3ac48c2d4 Move to a requirements-first approach
Add doc/requirements/, a structured set of normative requirements
extracted from the current ocserv implementation (internal/*.md,
generated with the requirements-from-implementation protocol) and
from the OpenConnect/AnyConnect protocol sources, reconciled into
protocol/unified.md.

Update AGENTS.md so that new features and bug fixes are documented as
requirements first: find or add the relevant REQ-* entry (with
acceptance criteria) and update the implied tests before changing
code, and confirm in merge requests that existing requirements and
use-cases still hold.

This follows partially https://github.com/microsoft/PromptKit

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-15 18:54:38 +02:00
Nikos Mavrogiannopoulos 8e8efd33a6 ai: added security-auditor persona
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-15 18:54:23 +02:00
Nikos Mavrogiannopoulos 4f187578c3 .gitignore/doc: removed legacy files
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-14 18:08:00 +02:00
Nikos Mavrogiannopoulos ea253803e7 Merge branch 'tmp-make' into 'master'
Do not reference make

See merge request openconnect/ocserv!584
2026-06-14 13:26:20 +00:00
Dimitri Papadopoulos 196350abc1 CONTRIBUTING.md: do not reference make
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-06-14 14:00:46 +02:00
Dimitri Papadopoulos Orfanos fa0a7db1cd Merge branch 'tmp-include' into 'master'
Consistent include files and directives

See merge request openconnect/ocserv!569
2026-06-14 09:35:13 +03:00
Nikos Mavrogiannopoulos 80ce55ae8f Merge branch 'tmp-CID-646042' into 'master'
Suppress Coverity Scan false positive

See merge request openconnect/ocserv!546
2026-06-13 05:45:25 +00:00
Nikos Mavrogiannopoulos 29dd18ddc5 tests: add SIGKILL fallback in cleanup_client_server
Ensure that ocserv is killed within bounded time by falling
back to a SIGKILL if ocserv does not stop on time.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-11 15:40:37 +02:00
Nikos Mavrogiannopoulos eeef24e520 tests: do not skip if /usr/sbin/ip is missing
This is to prevent an accidental skipping of the test.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-11 15:40:37 +02:00
Nikos Mavrogiannopoulos 826fe0ff30 tests: attempt to fix disconnect-user race that caused 300 s timeouts
After the occtl disconnect, poll 'occtl show user test' until the
session is gone before attempting the reconnect.  This guarantees that
session_close() has already returned and main's event loop is free to
process the reconnect worker's AUTH_COOKIE_REQ.

Addresses intermittent failures observed in the Fedora, CentOS9, and
CentOS10 CI jobs.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-11 15:40:37 +02:00
Nikos Mavrogiannopoulos 3f4a1f0e68 tests: reduce parallelization in asan
Often certain tests when run under asan will fail with out of memory.
Reduce parallelization for these tests when run under asan to reduce
memory pressure.

Example:
https://gitlab.com/openconnect/ocserv/-/jobs/14724892759

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-11 15:40:37 +02:00
Nikos Mavrogiannopoulos 6d778ebadb tests: pam-stack-guard: guard against tail optimizations of gcc
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-10 20:52:56 +02:00
Dimitri Papadopoulos c4fdd29a45 Suppress Coverity Scan false positive
** CID 646042:       Insecure data handling  (INTEGER_OVERFLOW)
/src/isolate.c: 59           in compute_worker_data_limit()

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-06-07 10:15:09 +02:00
Nikos Mavrogiannopoulos 49f9956eee release.sh: do not reference make
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
1.5.0
2026-06-07 08:35:33 +02:00
Nikos Mavrogiannopoulos a4a8126c7b doc update
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-07 08:30:26 +02:00
Nikos Mavrogiannopoulos b7a73b968d parse_data(): ensure sanity checks for safety
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-07 08:29:52 +02:00
Nikos Mavrogiannopoulos 9866624118 tun_write(): check input value for sanity
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-07 08:29:52 +02:00
Nikos Mavrogiannopoulos c5c921528d worker: reject client MTU below MIN_MTU to prevent unsigned underflow
DATA_MTU(ws, mtu) performs unsigned subtraction.  A client advertising
X-CSTP-Base-MTU or X-CSTP-MTU smaller than the combined DTLS overhead
(IP + UDP + DTLS record + crypto) causes the result to wrap to ~UINT_MAX,
which then reaches memset(), tun_read(), and IPC calls.

Fix: enforce MIN_MTU(ws) (800 for IPv4, 1280 for IPv6) as the lower
bound when accepting client-supplied link_mtu and tunnel_mtu values.
Values below the floor are logged and ignored; the server's own MTU
is used instead.  Add a defense-in-depth lower-bound check in
link_mtu_set() and a runtime assert after calc_mtu_values() that fires
in CI if a future cipher or protocol change erodes the safety margin.

Resolves: #717

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-07 08:29:52 +02:00
Nikos Mavrogiannopoulos 77097440eb worker: fix heap buffer overflow in webvpncontext= cookie decoding
An unauthenticated client could send a Cookie header with a webvpncontext=
value long enough that its base64-decoded length far exceeded SID_SIZE (32
bytes).  The decoder wrote directly into ws->sid without a prior length
check, overwriting adjacent fields in worker_st and crashing the worker.

The webvpn= cookie already had the correct pattern: check decoded length
bounds before decoding, decode into the ws->buffer scratch area, then
memcpy into the target only on an exact-size match.  Apply the same
pattern to webvpncontext=.

Resolves: #719

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-07 08:29:52 +02:00
Nikos Mavrogiannopoulos 8aa1022696 tests: add reproducer for oversized webvpncontext=/webvpn= cookie overflow
Sending a Cookie header with a webvpncontext= value whose base64-decoded
length exceeds SID_SIZE crashes the worker with SIGSEGV before it can
send an HTTP response.  The test detects both pre- and post-response
crashes: a connection reset (HTTP 000) and a "died with sigsegv" entry
in the server log respectively.

Relates: #719

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-07 08:29:52 +02:00
Nikos Mavrogiannopoulos 235882cebf doc update
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-06-07 08:27:25 +02:00