1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Security module for shell-tunnel.
//!
//! **Two of the three things here are defences this server applies; the third is
//! a primitive it offers and does not use.** They were listed together as
//! "provided for the API layer", which reads as three active defences and is
//! not what happens.
//!
//! ## Applied by the server, on every request
//!
//! - **API key authentication** — bearer tokens, scoped by capability
//! ([`auth`], [`capability`]).
//! - **Rate limiting** — per-address sliding window ([`rate_limit`]).
//!
//! ## Offered, and not applied
//!
//! - **Command validation** ([`validation`]) — [`CommandValidator`],
//! [`looks_like_injection`] and the rest are **not called from any execute
//! path**. A command sent to `/execute` reaches the shell without passing
//! through them, and nothing here is a barrier between a caller and the
//! machine; the barriers are the two above, plus [`crate::fs::FsRoot`] on the
//! filesystem routes.
//!
//! Whether to wire it is an open product question rather than an oversight: a
//! substring blocklist on by default is a trade a run-anything tool has to
//! choose deliberately. Until it is chosen, this stays a primitive a consumer
//! may apply to its own input before calling — which is a real use, and the
//! reason it is still exported.
//!
//! ## Example
//!
//! ```rust
//! use shell_tunnel::security::{ApiKeyStore, RateLimiter, CommandValidator};
//!
//! // Applied by the server: authentication …
//! let auth = ApiKeyStore::default();
//! auth.add_key("my-secret-key");
//!
//! // … and rate limiting (100 req/min).
//! let limiter = RateLimiter::default();
//!
//! // Offered, not applied: a consumer may run this over its own input before
//! // calling the API. The server does not.
//! let validator = CommandValidator::default();
//! assert!(validator.validate_command("echo hello").is_ok());
//! ```
// Re-export commonly used types
pub use ;
pub use ;
pub use ;
pub use ;