You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Server CLI (`bssh-server`)** - Server management commands including host key generation, password hashing, config validation (see main ARCHITECTURE.md)
37
37
-**SSH Server Module** - SSH server implementation using russh (see main ARCHITECTURE.md)
38
38
-**Server Authentication** - Authentication providers including public key verification (see main ARCHITECTURE.md)
39
39
-**SFTP Handler** - SFTP subsystem with path traversal prevention and chroot-like isolation (see main ARCHITECTURE.md)
40
+
-**SCP Handler** - SCP protocol with sink/source modes and security controls (see main ARCHITECTURE.md)
The bssh-server supports file transfers via the SCP (Secure Copy Protocol) command. Unlike SFTP which uses a dedicated subsystem, SCP operates through SSH exec requests.
492
+
493
+
### Protocol Overview
494
+
495
+
SCP is not a standalone protocol but a command-line tool that communicates over SSH. When a client runs `scp file user@host:path`:
496
+
1. The SSH client establishes a connection to the server
497
+
2. The server receives an exec request for `scp -t path` (upload) or `scp -f path` (download)
498
+
3. The server spawns the SCP handler to manage the file transfer
499
+
500
+
### Operation Modes
501
+
502
+
**Sink Mode (`-t` flag)**: Server receives files from client (upload)
503
+
```bash
504
+
# Client uploads file.txt to server's /tmp directory
505
+
scp file.txt user@server:/tmp/
506
+
```
507
+
508
+
**Source Mode (`-f` flag)**: Server sends files to client (download)
509
+
```bash
510
+
# Client downloads file.txt from server
511
+
scp user@server:/home/user/file.txt ./
512
+
```
513
+
514
+
### SCP Command Flags
515
+
516
+
| Flag | Description |
517
+
|------|-------------|
518
+
| `-t` | Sink mode (target/upload) |
519
+
| `-f` | Source mode (from/download) |
520
+
| `-r` | Recursive transfer for directories |
521
+
| `-p` | Preserve file modification times |
522
+
| `-d` | Target is expected to be a directory |
523
+
| `-v` | Verbose mode |
524
+
525
+
### Security Features
526
+
527
+
The SCP handler implements multiple security measures:
528
+
529
+
**Path Traversal Prevention:**
530
+
- All paths are normalized before processing
531
+
- `..`components are resolved without escaping the root directory
532
+
- Absolute paths are stripped and joined with the user's root directory
533
+
534
+
**Symlink Escape Prevention:**
535
+
- Existing paths are canonicalized to resolve symlinks
536
+
- If the canonical path is outside the root directory, access is denied
537
+
- Symlinks in recursive transfers are skipped for security
538
+
539
+
**Input Validation:**
540
+
- Filenames cannot contain `/`, `..`, or `.`
541
+
- File size is limited to 10 GB maximum
542
+
- Permission mode bits are masked to strip setuid/setgid/sticky bits (only 0o777 allowed)
543
+
- Protocol line length is limited to prevent DoS via buffer exhaustion
0 commit comments