Skip to content

Fix length check when accepting SFTP connections - #186

Merged
notAreYouScared merged 1 commit into
mainfrom
QuintenQVD0/SSH-DDOS
Jun 19, 2026
Merged

Fix length check when accepting SFTP connections#186
notAreYouScared merged 1 commit into
mainfrom
QuintenQVD0/SSH-DDOS

Conversation

@QuintenQVD0

@QuintenQVD0 QuintenQVD0 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Changes

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness of SFTP subsystem request handling by adding defensive validation to prevent potential errors during request processing.

@QuintenQVD0
QuintenQVD0 requested a review from a team as a code owner June 18, 2026 11:13
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fce87868-5cfb-420e-9d96-e2cb2bf92cc7

📥 Commits

Reviewing files that changed from the base of the PR and between 565b0e3 and 57e7786.

📒 Files selected for processing (1)
  • sftp/server.go
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build and Test (ubuntu-22.04, 1.25.7, linux, amd64)
  • GitHub Check: Build and Test (ubuntu-22.04, 1.26.0, linux, amd64)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
sftp/server.go (1)

146-147: Security fix correctly prevents panic on short payloads.

The addition of len(req.Payload) >= 4 before slicing prevents a potential DoS vulnerability where an attacker could send a malformed SSH request with a payload shorter than 4 bytes, causing a panic. The short-circuit evaluation of && ensures the slice operation only occurs when the length check passes.

The implementation correctly assumes SSH subsystem request payloads follow the SSH string wire format (4-byte big-endian length prefix + string data), and the check properly validates this assumption before attempting to slice. The code safely handles all edge cases:

  • Payloads shorter than 4 bytes are rejected without panic
  • Payloads of exactly 4 bytes correctly reject empty string comparisons
  • Valid payloads containing "sftp" are properly accepted

📝 Walkthrough

Walkthrough

In sftp/server.go, the AcceptInbound function now checks that req.Payload is at least 4 bytes long before slicing it. The subsystem match condition is extracted into an ok boolean, which is passed directly to req.Reply(ok, nil).

Changes

SFTP Payload Guard

Layer / File(s) Summary
Payload bounds check in AcceptInbound
sftp/server.go
Adds len(req.Payload) >= 4 guard before slicing req.Payload[4:]; extracts the combined condition into an ok boolean used in req.Reply.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A bunny once sliced without checking the size,
And panicked one day — what a dreadful surprise!
Now four little bytes must be present and there,
Before any slicing is done with great care.
🐇 Hop safely, dear payload, no index out of bounds! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix length check when accepting SFTP connections' directly and accurately describes the main change in the PR, which defensively adds a length check when accepting SFTP subsystem requests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch QuintenQVD0/SSH-DDOS

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@notAreYouScared
notAreYouScared merged commit 4ba0274 into main Jun 19, 2026
7 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.

3 participants