Skip to content

cf-serverd: Fixed path ACL bypass through dangling symlink requests - #6509

Open
Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:serverd-dangling-symlink-acl
Open

Dhanu-dynamic wants to merge 1 commit into
cfengine:masterfrom
Dhanu-dynamic:serverd-dangling-symlink-acl

Conversation

@Dhanu-dynamic

Copy link
Copy Markdown
Contributor

PreprocessRequestPath() (TLS protocol) and AccessControl() (classic protocol) canonicalise the requested path with realpath() before matching it against the path ACL, and that match is a plain string prefix check. realpath() fails on a dangling symlink, and both functions then fell back to the path exactly as the client sent it, with .. components and symlinked directories unresolved. A client admitted to /srv/admitted could request /srv/admitted/../../etc/some-dangling-link: lstat() resolves it outside the admitted tree, while the prefix match admits it (and deny rules miss it). STAT then returns the lstat() metadata and readlink() target of any dangling symlink on the server.

For a dangling symlink, canonicalise its parent directory with realpath() and append the link name instead. The classic branch also no longer reads statbuf after a failed lstat().

The new test_preprocess_request_path_dangling_symlink in tests/unit/protocol_test.c requests <tmp>/admitted/../dangling and expects <tmp>/dangling; before the change the raw path comes back. I checked the helper with a standalone harness (old fallback admits the .. path under a /srv/admitted prefix rule, new one yields /etc/dangling and is refused), but have not run the full autotools build and unit suite on Linux yet; CI will confirm.

PreprocessRequestPath() (TLS protocol) and AccessControl() (classic
protocol) canonicalise the requested path with realpath() before matching
it against the path ACL, and that match is a plain string prefix check.
realpath() fails on a dangling symlink, and both functions then fell back
to the path exactly as the client sent it, with '..' components and
symlinked directories unresolved. A client admitted to /srv/admitted could
request /srv/admitted/../../etc/some-dangling-link: lstat() resolves it
outside the admitted tree, while the prefix match admits it (and deny
rules miss it). STAT then returns the lstat() metadata and readlink()
target of any dangling symlink on the server.

For a dangling symlink, canonicalise its parent directory with realpath()
and append the link name instead. The classic branch also no longer reads
statbuf after a failed lstat().

Changelog: Title
Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant