Skip to content

fix: harden the SFTP endpoint (security review findings) - #4

Merged
ValgulNecron merged 3 commits into
mainfrom
fix/security-review-hardening
Nov 24, 2026
Merged

ValgulNecron merged 3 commits into
mainfrom
fix/security-review-hardening

Conversation

@ValgulNecron

Copy link
Copy Markdown
Contributor

Fixes the four findings of the SFTP security review, plus what a follow-up review of the exposed and internal sides found. Each finding was checked against the code first.

Findings and fixes

Finding Verified in code Fix
Unbounded channels per connection (High) handle accepted every session channel and started a goroutine for it. The one-SFTP guard ran only once a request arrived, and a channel that sent no request stayed open until the idle timeout. At most 2 session channels per connection; a further open is rejected with resource-shortage before Accept. A session channel that has not started SFTP within LoginTimeout (10 s) is closed.
API hop may run without TLS (High if http) validateBaseURL accepted http://, and the default http.Client follows redirects: on 307/308 it re-sends the login body (password or key) and, for a same-host redirect, the bearer header. New requires https unless AllowInsecureHTTP (--allow-insecure-api, GAMEPLANE_SFTP_ALLOW_INSECURE_API) is set. Both HTTP clients refuse every redirect (ErrUseLastResponse, so a 3xx maps to ErrFailure).
Revocation-poll errors leave connections open (Medium) checkOnce returned on any error and kept every connection. ExpiresAt was parsed but never used. Fails closed: a connection whose session the API has not confirmed for RevalidateWithin (2 min), or whose known expiry has passed without a confirmation, is closed (gameplane_sftp_unconfirmed_closed_total). A login whose session is already expired is refused. A single failed check still keeps connections, so a short API blip does not drop users.
Metrics on all interfaces (Medium if reachable) Default :9102, no auth, every path served. (The chart's public Service lists only ssh, and the NetworkPolicy allows only the SFTP port.) Default 127.0.0.1:9102; serves only GET /metrics; read, write and idle timeouts. The chart change (bind to the pod address only when a ServiceMonitor scrapes it) is in the Gameplane PR.

Found by the follow-up review

  • One source IP could take all 64 pre-auth slots (holding each for the 10 s handshake deadline), locking every other user out. New per-IP cap --max-preauth-per-ip (default 8).
  • A 401 on a file request (session already revoked or expired at the API) left the connection open until the next check. The file system now reports it through Options.OnUnauthorized, and the server closes that connection at once (Server.Revoke).

The API side (active SFTP transfers are re-checked against the session on SQLite too, and a long transfer keeps its session alive) and the chart changes are in the matching Gameplane PR. That PR also bumps this submodule once this PR merges.

Tests

New tests only (*/hardening_test.go, internal/vfs/unauthorized_test.go, main_hardening_test.go), plus two optional fields on the existing fakeAPI test helper (checkErr, expiresIn; zero values keep the old behaviour). A fresh reviewer that saw only the test diff found no weakened or deleted changes. Docs: specs.md and README.md updated.


Generated by Claude Code

- Cap session channels per connection at 2, rejecting more before they
  are accepted, and close a session channel that has not started SFTP
  within LoginTimeout.
- Require an https API URL unless --allow-insecure-api is set, and never
  follow a redirect from the API, so credentials are not re-sent.
- Fail closed on session checks: close a connection whose session the
  API has not confirmed for RevalidateWithin (2m) or whose known expiry
  passed; refuse a login whose session is already expired; close a
  connection at once when the API answers 401 on a file request.
- Bind /metrics to 127.0.0.1 by default, serve only GET /metrics, and
  add I/O timeouts to the metrics server.
- Cap pre-auth connections per source IP (--max-preauth-per-ip, 8), so
  one address cannot take every pre-auth slot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68e159fe-0869-40e2-b122-69754411cbb0
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

url.Parse lowercases the scheme, but the https check compared the raw
string, so HTTP://... slipped past it without --allow-insecure-api.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
@ValgulNecron
ValgulNecron marked this pull request as ready for review November 24, 2026 00:30
@ValgulNecron
ValgulNecron merged commit 9cf72d5 into main Nov 24, 2026
6 checks passed
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.

2 participants