Commit 9a0f7e0
authored
feat: Implement file transfer filtering infrastructure (#164)
* feat: Implement file transfer filtering infrastructure
Add a complete filtering infrastructure for SFTP and SCP file transfer operations:
- TransferFilter trait with check() and check_with_dest() methods
- Operation enum: Upload, Download, Delete, Rename, CreateDir, ListDir, Stat, SetStat, Symlink, ReadLink
- FilterResult: Allow, Deny, Log actions
- FilterPolicy engine with first-match-wins rule evaluation
- Matcher trait for extensible path matching
Built-in matchers:
- GlobMatcher: wildcard patterns (*.key, *.pem)
- RegexMatcher: full regex support
- PrefixMatcher: directory tree matching (/etc/*)
- ExactMatcher: specific file matching
- ComponentMatcher: match path components (.git, .ssh)
- ExtensionMatcher: file extension matching
- CombinedMatcher: OR-combine multiple matchers
- NotMatcher: invert matcher results
Configuration:
- Extended FilterConfig with default_action, rule names, operations, and users
- FilterRule supports per-user and per-operation restrictions
- YAML configuration via existing config loader
Closes #138
* fix(quality): resolve clippy warnings in filter module
Priority: MEDIUM
Issue: Three clippy warnings causing build failures with -D warnings
- Derive Default instead of manual impl for FilterResult
- Remove needless borrow in rule_from_config()
- Rename CombinedMatcher::add() to with_matcher() to avoid confusion with std::ops::Add
Review-Iteration: 1
* fix(security): add ReDoS protection to RegexMatcher
Priority: HIGH
Issue: RegexMatcher accepted arbitrary regex patterns without complexity limits,
allowing potential CPU exhaustion via crafted patterns
- Use RegexBuilder with size_limit and dfa_size_limit (1MB default)
- Add with_size_limit() constructor for custom limits
- Add test for size limit functionality
Review-Iteration: 1
* fix(security): add GlobMatchMode for explicit control over glob matching
Priority: HIGH
Issue: GlobMatcher tried both full path and filename matching, which could
lead to unintended matches in security-sensitive filtering
- Add GlobMatchMode enum (PathOrFilename, FullPathOnly, FilenameOnly)
- Add with_mode() constructor for explicit control
- Document matching behavior and security implications
- Add tests for each match mode
Review-Iteration: 1
* fix(security): add normalize_path for path traversal protection
Priority: CRITICAL
Issue: Path matchers operated on raw paths without normalization, allowing
bypass via path traversal sequences like ../
- Add normalize_path() function for logical path normalization
- Add comprehensive security documentation
- Document that callers should normalize paths before matching
- Add tests demonstrating the security issue and fix
Review-Iteration: 1
* test: add comprehensive test coverage for filter module
- Add tests for FilterPolicy.from_config() with glob patterns and prefixes
- Add tests for FilterPolicy accessor methods (rule_count, default_action)
- Add tests for FilterRule.matches() with all conditions
- Add tests for SharedFilterPolicy (check_with_dest, From impl)
- Add tests for Operation.all() and additional parse/display tests
- Add tests for matcher accessor methods (prefix, path, component, extension)
- Add tests for GlobMatchMode enum and CombinedMatcher len/is_empty
- Fix normalize_path tests placement (move inside test module)
- Update ARCHITECTURE.md with File Transfer Filter module documentation1 parent 4147b29 commit 9a0f7e0
7 files changed
Lines changed: 2724 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
216 | 317 | | |
217 | 318 | | |
218 | 319 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
278 | 284 | | |
279 | 285 | | |
280 | 286 | | |
| |||
285 | 291 | | |
286 | 292 | | |
287 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
288 | 300 | | |
289 | 301 | | |
290 | 302 | | |
| 303 | + | |
291 | 304 | | |
292 | 305 | | |
293 | 306 | | |
294 | 307 | | |
295 | 308 | | |
| 309 | + | |
296 | 310 | | |
297 | 311 | | |
298 | 312 | | |
299 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
300 | 327 | | |
301 | 328 | | |
302 | 329 | | |
303 | | - | |
| 330 | + | |
304 | 331 | | |
305 | 332 | | |
306 | 333 | | |
| 334 | + | |
307 | 335 | | |
308 | 336 | | |
309 | 337 | | |
| |||
0 commit comments