Repository navigation
fix: harden the SFTP endpoint (security review findings) - #4
Merged
Merged
Conversation
- 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>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
handleaccepted everysessionchannel 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.resource-shortagebeforeAccept. A session channel that has not started SFTP withinLoginTimeout(10 s) is closed.validateBaseURLacceptedhttp://, and the defaulthttp.Clientfollows redirects: on 307/308 it re-sends the login body (password or key) and, for a same-host redirect, the bearer header.NewrequireshttpsunlessAllowInsecureHTTP(--allow-insecure-api,GAMEPLANE_SFTP_ALLOW_INSECURE_API) is set. Both HTTP clients refuse every redirect (ErrUseLastResponse, so a 3xx maps toErrFailure).checkOncereturned on any error and kept every connection.ExpiresAtwas parsed but never used.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.:9102, no auth, every path served. (The chart's public Service lists onlyssh, and the NetworkPolicy allows only the SFTP port.)127.0.0.1:9102; serves onlyGET /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
--max-preauth-per-ip(default 8).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 existingfakeAPItest 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.mdandREADME.mdupdated.Generated by Claude Code