Commit Graph
4150 Commits
Author SHA1 Message Date
Dimitri Papadopoulos 6eb1cef514 This is a Bash script, not plain Bourne
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-09 10:16:00 +02:00
Dimitri Papadopoulos c30bd5dca4 Address build warning
[libprotobuf WARNING protoc-gen-c/main.cc:44] `protoc-c` is deprecated. Please use `protoc` instead!

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-09 10:16:00 +02:00
Nikos Mavrogiannopoulos 2548a27b51 Merge branch 'tmp-AF_INET' into 'master'
Build on FreeBSD

See merge request openconnect/ocserv!514
2026-05-07 01:56:53 +00:00
Dimitri Papadopoulos eb886a7c67 Include <sys:socket.h> for AF_INET
Required to build on FreeBSD 15.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-06 20:33:03 +02:00
Nikos Mavrogiannopoulos 22bbad4eb5 worker: add per-worker memory limit via RLIMIT_DATA
Introduce a per-worker heap cap as defense-in-depth against
memory-exhaustion DoS attacks. The limit uses RLIMIT_DATA rather
than RLIMIT_AS: since Linux 4.7 RLIMIT_DATA covers brk and private
anonymous mmap regions, i.e, the paths used by malloc and talloc, while
ignoring shared-library file mappings that inflate RLIMIT_AS without
reflecting actual allocation.

This aligns with haproxy's handling. See also:
https://github.com/torvalds/linux/commit/84638335900f1995495838fe1bd4870c43ec1f67
https://sources.debian.org/src/haproxy/3.2.17-1/src/limits.c?hl=486#L486
https://www.kernel.org/doc/html/latest/mm/overcommit-accounting.html

The cap is computed at worker startup by reading the data+stack field
from /proc/self/statm.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-06 13:54:40 +02:00
Nikos Mavrogiannopoulos 4303a12f60 worker: harden HTTP request header size limits
Bound memory growth in the worker for unauthenticated connections by
enforcing HTTP headers limit in addition to HTTP body limit.

Resolves: #712

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-06 13:54:21 +02:00
Nikos Mavrogiannopoulos 7efa74f8e8 protobuf files were removed from the repository
This is a follow-up to a65f2c22a2
which did not actually remove the files.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-03 19:15:55 +02:00
Nikos Mavrogiannopoulos 8e0f7f460a Merge branch 'tmp-llhttp_cb' into 'master'
llhttp callbacks should return -1 on error

See merge request openconnect/ocserv!537
2026-05-03 17:05:13 +00:00
Dimitri Papadopoulos 9cc845e9d3 llhttp callbacks should return -1 on error
https://github.com/nodejs/llhttp#llhttp_settings_t

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-03 18:41:38 +02:00
Nikos Mavrogiannopoulos 8913ffadff doc: updated for nft/iptables dependencies
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-02 18:49:43 +02:00
Nikos Mavrogiannopoulos 4c85218f41 .gitignore: removed leftovers from autotools
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-02 17:21:42 +02:00
Nikos Mavrogiannopoulos 9c44e09356 ocserv-fw-nftables: replace ipcalc with pure-shell mask_to_prefix
ipcalc was used only to convert dotted-decimal subnet masks to CIDR
prefix lengths (e.g. 255.255.0.0 -> 16), replaced with a POSIX shell
script.

Relates: #709

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-02 17:21:38 +02:00
Nikos Mavrogiannopoulos dcb1b8d24e Merge branch 'tmp-prefer-nft' into 'master'
meson: nftables is preferred unless only iptables is found

See merge request openconnect/ocserv!531
2026-05-02 15:09:43 +00:00
Nikos Mavrogiannopoulos 465d3ce383 Merge branch 'tmp-framed-ipv6' into 'master'
radius-auth: fix Framed-IPv6-Prefix routes being silently dropped

Closes #710

See merge request openconnect/ocserv!532
2026-05-01 20:21:09 +00:00
Nikos Mavrogiannopoulos dda2015aa4 meson: nftables is preferred unless iptables is explicitly requested
Relates: #709

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-01 22:17:04 +02:00
Nikos Mavrogiannopoulos c41b6d52de Merge branch 'tmp-CID-645850' into 'master'
Fix new Coverity Scan defect

See merge request openconnect/ocserv!530
2026-05-01 19:26:45 +00:00
Dimitri Papadopoulos OrfanosandNikos Mavrogiannopoulos c0b282576e Fix new Coverity Scan defect
This adds checks in memory allocation, to address the following issue reported by coverity:
** CID 645850:       Null pointer dereferences  (FORWARD_NULL) /tests/ban-ips.c: 84           in main()

Signed-off-by: default avatarDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-01 19:26:45 +00:00
Nikos Mavrogiannopoulos e7d79e232d radius-auth: fix Framed-IPv6-Prefix routes being silently dropped
When processing a RADIUS Access-Accept with Framed-IPv6-Prefix, the code
passed the wrong value for it. Corrected by passing the actual prefix.

Fixes: #710

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-01 16:31:38 +02:00
Nikos Mavrogiannopoulos ac5ee6a10b Merge branch 'type-limits-warning' into 'master'
Fix compiler warning when PAM/RADIUS are disabled

See merge request openconnect/ocserv!529
2026-05-01 14:12:10 +00:00
Grigory Trenin 86972b7200 Fix compiler warning when PAM/RADIUS are disabled
This fixes a -Wtype-limits warning encountered in builds without
PAM and RADIUS (e.g., OpenWRT). When the avail_acct_types array is
empty, ARRAY_SIZE evaluates to 0, making the unsigned comparison
always false.

Reported in #709.

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-27 12:00:09 -04:00
Nikos Mavrogiannopoulos 4334978fd6 Merge branch 'tunnel-all-dns' into 'master'
Fix tunnel-all-dns ignored in user config

Closes #708

See merge request openconnect/ocserv!527
2026-04-27 03:54:29 +00:00
Grigory Trenin a79e2f1cd5 Respect tunnel-all-dns in per-user/group config
Ensure that 'tunnel-all-dns' setting is honoured when overridden
in user or group-specific configuration files.

Resolves: #708

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-26 21:05:06 -04:00
Nikos Mavrogiannopoulos 54e3244b45 tests: fix radius failures with radcli 1.5.0
radcli 1.5.0 validates Message-Authenticator in RADIUS responses
CVE-2024-3596 (BlastRADIUS) and silently discards responses that lack
it.  Make sure that the Message-Authenticator message is known to
the client via the dictionary.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-25 19:40:56 +02:00
Nikos Mavrogiannopoulos 5148c723cb tests: fix flaky radius tests by waiting for server readiness
All six radius tests used a fixed sleep 4 after starting radiusd and
ocserv.  On slow or ASAN-instrumented hosts (CentOS 10 CI) this is
insufficient: freeradius with -xx debug logging takes longer than 4
seconds to load its modules, and even after binding UDP 1812 it continues
initializing its user database before it can process auth requests.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-25 17:20:38 +02:00
Nikos Mavrogiannopoulos 5137ba4309 ai: add AI policy
CONTRIBUTING.md: new AI Assistance Policy section stating that AI use is
assumed and requires no disclosure, that human accountability is what
matters, and that reviewers may request additional explanation for
submissions showing signs of unchecked generation.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-25 12:08:32 +02:00
Nikos Mavrogiannopoulos 855966cd95 ai: add AI guidance, personas
Introduce a structured AI assistance framework for the project:

- AGENTS.md: single, comprehensive AI guidance file for all tools
  (Claude Code, Codex, Copilot, Cursor). Covers the privilege-separation
  architecture invariant, build/test instructions, code style (including
  a rule against deep preprocessor conditionals), memory allocator policy,
  IPC modification procedure, module-specific doc pointers, and a
  contribution checklist split into agent-runnable and human-judgment items.
  Includes a security disclosure gate that redirects potential vulnerability
  reports to the confidential issue tracker before any public MR is opened.

- contrib/ai/personas/ocserv-core-dev.md: maintainer-facing persona with
  project-specific protocols for anti-hallucination (GnuTLS/protobuf/seccomp
  APIs), memory safety (talloc-first, gnutls_malloc exception), a taxonomy
  of ocserv-specific vulnerability classes, and a self-verification protocol
  that distinguishes what an agent can check automatically from what requires
  human judgment.

- contrib/ai/personas/ocserv-contributor.md: external-contributor-facing
  persona with mandatory architecture orientation, a prominent security
  disclosure gate, five hard guardrails (privilege boundary, syscall
  portability, GnuTLS-only, protobuf regeneration, talloc), and a
  step-by-step workflow for features, bug fixes, and security fixes.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-25 12:08:32 +02:00
Nikos Mavrogiannopoulos a65f2c22a2 protobuf source files are generated during release
Protobuf files are removed from the repository and are only
auto-generated during dist.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-23 19:21:27 +02:00
Nikos Mavrogiannopoulos 58a67f14f3 config: extend vhost_inherit_static_config to cover vhost-scoped fields
All [scope: vhost (non-reloadable)] fields in static_cfg_st now inherit
from the default vhost when not explicitly set in a named-vhost section,
consistent with how ReloadableConfig fields already behave.  This means
a named vhost that shares the same TLS cert, CA, auth method, or PKCS#11
pins as the default no longer has to repeat them.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-23 10:51:26 +02:00
Nikos Mavrogiannopoulos 112afa683c config: treat expose-iroutes as a normal configuration option
That is store it in VhostConfig and avoid manual clearing of it.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-22 20:29:26 +02:00
Nikos Mavrogiannopoulos 836e6f0785 config: fix scope annotation and vhost guards for global-only options
NetworkConfig.name ('device' key) is global-only: the parser calls
error_on_vhost() and tun.c always reads it from the default vhost.
Annotate it as [scope: global] in cfg.proto to match the implementation.

Also add missing error_on_vhost() guards to the deprecated aliases
'use-seccomp' (for isolate-workers), 'use-dbus' (for use-occtl) and
'min-reauth-time' (for ban-time). Their canonical replacements already
reject vhost use; the aliases did not.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-22 20:29:24 +02:00
Nikos Mavrogiannopoulos 139ff827d9 config: restructure per-vhost configuration for clarity and maintainability
Introduce a protobuf-generated ReloadableConfig (cfg.proto) to hold all
fields that reload on SIGHUP, and separate them from static_cfg_st, which
holds fields that require a server restart.  Named vhosts inherit from the
default vhost via a pack/unpack round-trip. Adding a new config field
only requires editing cfg.proto.  Struct and accessor names (ReloadableConfig,
static_cfg_st, GETRCONFIG, GETSCONFIG) now reflect each field's lifetime.
A new unit test covers the full inheritance path.

Resolves: #705

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-22 20:29:15 +02:00
Nikos Mavrogiannopoulos 1228688fb2 Merge branch 'tmp-rfc1123' into 'master'
valid_hostname: enhance to cover RFC 1123 requirements

See merge request openconnect/ocserv!525
2026-04-22 11:20:05 +00:00
Nikos Mavrogiannopoulos caacc92c28 Merge branch 'doc-user-config' into 'master'
doc: clarify reload behavior for per-user/group configs

See merge request openconnect/ocserv!526
2026-04-21 18:58:01 +00:00
Nikos Mavrogiannopoulos 745d7883be design.md: include auth state in the diagram
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-21 19:19:32 +02:00
Nikos Mavrogiannopoulos 56055a2ed0 Merge branch 'udp-desync' into 'master'
Do not forward UDP until client is authenticated

Closes #706

See merge request openconnect/ocserv!522
2026-04-21 16:42:35 +00:00
Grigory Trenin eddd29f59b Do not forward UDP until client is authenticated
Do not forward DTLS packets until the client is authenticated to
prevent the race between AUTH_COOKIE_REP and CMD_UDP_FD messages
on the command socket.

Closes #706

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-21 07:06:59 -04:00
Grigory Trenin 50c59cd53b doc: clarify reload behavior for per-user/group configs
Document that there is no need to reload ocserv after modifying per-user
or per-group configuration.

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-19 09:08:07 -04:00
Nikos Mavrogiannopoulos a9f42c892c valid_hostname: enhance to cover RFC 1123 requirements
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-18 15:51:20 +02:00
Nikos Mavrogiannopoulos 0f7640bcea Merge branch 'tmp-claude' into 'master'
RFC 952 prohibits trailing hyphen

See merge request openconnect/ocserv!523
2026-04-18 13:43:36 +00:00
Nikos Mavrogiannopoulos c0e3aa6c5c Merge branch 'tmp-disable-adaptive-rate-limit' into 'master'
Add check to disable adaptive rate limiting

Closes #493

See merge request openconnect/ocserv!476
2026-04-18 13:32:07 +00:00
Dimitri Papadopoulos c4767470eb RFC 952 prohibits trailing hyphen, not only leading hyphen
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-04-17 22:33:11 +02:00
Dimitri Papadopoulos 99650ec7cb Add check to disable adaptive rate limiting
Disable when targeting Linux kernels that do not support Unix socket
monitoring (UNIX_DIAG), like the default OpenWrt kernel.

This will avoid flooding the log with this error message:
	NLM query failed

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-04-17 21:58:37 +02:00
Nikos Mavrogiannopoulos da90b76b07 bumped versions
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-17 00:08:27 +02:00
Nikos Mavrogiannopoulos c520accb84 Released 1.4.2
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
1.4.2
2026-04-16 23:27:59 +02:00
Nikos Mavrogiannopoulos 537e171664 worker-auth: require exact session_id length in cookie auth reply
recv_cookie_auth_reply() used > instead of != when validating
msg->session_id.len, allowing a shorter-than-expected length to
pass. ws->session_id is always consumed at full sizeof() by the
DTLS session setup; a short fill would leave stale tail bytes.
Align with the stricter != check used in recv_auth_reply().

proxy-proto: abort on zero-length unknown TLV in parse_ssl_tlvs()

An unknown TLV with length == 0 caused an infinite loop: the
AVAIL_HEADER_SIZE macro subtracted nothing and data did not
advance. Detect this and return early, consistent with how
AVAIL_HEADER_SIZE handles other malformed headers.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-16 23:05:34 +02:00
Nikos Mavrogiannopoulos 5d0a4dadc4 NEWS: documented updates
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-16 22:53:37 +02:00
Nikos Mavrogiannopoulos bc961061d1 worker: fix PP2_SUBTYPE_SSL_CN parsed as top-level TLV instead of sub-TLV
Per proxy protocol v2 spec §2.2.6, PP2_SUBTYPE_SSL_CN (0x22) is a
sub-TLV inside the PP2_TYPE_SSL body, not a top-level TLV in the TLV
stream.  The previous code looked for 0x22 at the top level, where
haproxy never sends it, so client certificate CN was never extracted
via proxy protocol.

Fix parse_ssl_tlvs() to scan the bytes after the fixed pp2_tlv_ssl
header as a nested sub-TLV loop when cert_auth_ok is set.

Also fix htons() -> ntohs() for the TLV length byte-swap (functionally
identical but semantically correct for a network-to-host conversion),
and update the misleading comment that claimed the field was
little-endian.

Add tests/proxyproto-v2.c, a unit test that feeds a binary proxy
protocol v2 packet with PP2_TYPE_SSL + PP2_SUBTYPE_SSL_CN sub-TLV
through parse_proxy_proto_header() and verifies that cert_auth_ok and
cert_username are populated correctly.  Also covers verify!=0, missing
CERT_SESS flag, no CN sub-TLV, and TCP conn_type (TLV parsing skipped).

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-16 22:46:41 +02:00
Nikos Mavrogiannopoulos a0504dd5a7 main: bound-check sec-mod message length before allocation
handle_sec_mod_commands() lacked an upper-bound check on the `length`
field received from the sec-mod socket before passing it to talloc_size().
The worker command handler already applies a MAX_MSG_SIZE guard.

Replace the redundant (int)length < 0 cast (impossible for uint32_t) with
a length > MAX_MSG_SIZE check, matching the pattern in handle_worker_commands().
Also fix the format specifier from %d to %u for the uint32_t length.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-16 22:46:41 +02:00
Nikos Mavrogiannopoulos 8355aa080e sec-mod: call sec_auth_user_deinit on all entries at teardown
On sec-mod exit, sec_mod_client_db_deinit() freed client entries via
talloc_free without first calling sec_auth_user_deinit(), leaving open
accounting sessions (RADIUS, PAM) and auth module state uncleaned.

Iterate over all entries and call sec_auth_user_deinit() before the
htable_clear/talloc_free teardown, matching the behaviour of the normal
del_client_entry -> clean_entry path.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-16 22:46:41 +02:00
Nikos Mavrogiannopoulos b37a2dd0de sec-mod: guard against NULL orig_remote_ip in auth init HMAC
protobuf-c sets absent string fields to NULL at runtime even when
marked required in the schema, contrary to the in-code comment.
Calling strlen(NULL) is undefined behaviour and crashes sec-mod.
A compromised worker could exploit this to deny authentication for
all connected clients.

Add an explicit NULL check before the strlen call, consistent with
the existing guard on the our_ip field.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-16 22:46:41 +02:00