Skip to content

Token storage permission checks and path traversal mitigation - #80

Open
pturbing wants to merge 3 commits into
mainfrom
pascal/sec-hardening
Open

pturbing wants to merge 3 commits into
mainfrom
pascal/sec-hardening

Conversation

@pturbing

Copy link
Copy Markdown

Tokenstorage

mode bits before the umask and a permissive umask could leave them
writable by other local users. When the token directory already exists,
validate it rather than trusting it: reject symlinks and non-directories,
group/other-writable dirs, and dirs not owned by the current user, closing
a path-replacement vector on shared hosts.

Path Traversal

clusterURL.Path, which sanitizedURL then swaps into Host, bypassing the
non-empty-path check. The unvalidated host was used directly as a filename in
filepath.Join(f.dir, cluster), letting import/login/logout/export read, write,
or delete files outside the token directory.

Enforce containment at the store boundary: Load/Store/Delete now operate through
an os.Root rooted at the token directory, so the OS rejects any "..", absolute
path, or symlink escape. Add a tokenFileName guard that rejects keys that are
not a single clean path element, giving a clear error at the CLI boundary.
Legitimate hosts (with or without a port) are single path elements and pass
through unchanged, so existing token files remain readable.

Add regression tests covering the traversal vectors and filename validation.

pturbing and others added 3 commits September 18, 2026 08:10
mode bits before the umask and a permissive umask could leave them
writable by other local users. When the token directory already exists,
validate it rather than trusting it: reject symlinks and non-directories,
group/other-writable dirs, and dirs not owned by the current user, closing
a path-replacement vector on shared hosts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
clusterURL.Path, which sanitizedURL then swaps into Host, bypassing the
non-empty-path check. The unvalidated host was used directly as a filename in
filepath.Join(f.dir, cluster), letting import/login/logout/export read, write,
or delete files outside the token directory.

Enforce containment at the store boundary: Load/Store/Delete now operate through
an os.Root rooted at the token directory, so the OS rejects any "..", absolute
path, or symlink escape. Add a tokenFileName guard that rejects keys that are
not a single clean path element, giving a clear error at the CLI boundary.
Legitimate hosts (with or without a port) are single path elements and pass
through unchanged, so existing token files remain readable.

Add regression tests covering the traversal vectors and filename validation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant