pub struct SecurityPolicy { /* private fields */ }Expand description
Unified security policy that coordinates all security checks
Implementations§
Source§impl SecurityPolicy
impl SecurityPolicy
Sourcepub fn new(workspace_dir: PathBuf) -> Self
pub fn new(workspace_dir: PathBuf) -> Self
Create a new security policy with default configuration
Sourcepub fn with_config(workspace_dir: PathBuf, config: SecurityConfig) -> Self
pub fn with_config(workspace_dir: PathBuf, config: SecurityConfig) -> Self
Create a new security policy with custom configuration
Sourcepub fn from_level(workspace_dir: PathBuf, level: SecurityLevel) -> Self
pub fn from_level(workspace_dir: PathBuf, level: SecurityLevel) -> Self
Create a new security policy from a security level preset
Sourcepub fn config(&self) -> &SecurityConfig
pub fn config(&self) -> &SecurityConfig
Get the security configuration
Sourcepub fn workspace_dir(&self) -> &Path
pub fn workspace_dir(&self) -> &Path
Get the workspace directory
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Check if read-only mode is enabled
Sourcepub fn has_shell_access(&self) -> bool
pub fn has_shell_access(&self) -> bool
Check if shell access is allowed (always false in standard mode)
Sourcepub fn is_path_allowed(&self, path: &str) -> Result<(), SecurityError>
pub fn is_path_allowed(&self, path: &str) -> Result<(), SecurityError>
Layer 1-5: Basic path validation (before resolution)
Checks for:
- Null bytes
- Path traversal (../)
- URL-encoded traversal
- Tilde expansion
- Forbidden prefixes
Sourcepub fn resolve_path(&self, path: &str) -> PathBuf
pub fn resolve_path(&self, path: &str) -> PathBuf
Resolve a path relative to the workspace
Sourcepub fn is_resolved_path_allowed(&self, resolved: &Path) -> bool
pub fn is_resolved_path_allowed(&self, resolved: &Path) -> bool
Layer 8: Check if a resolved (canonicalized) path is within allowed roots
Sourcepub async fn validate_path(&self, path: &str) -> Result<PathBuf, SecurityError>
pub async fn validate_path(&self, path: &str) -> Result<PathBuf, SecurityError>
Full path validation: from input to resolved path
Sourcepub async fn validate_parent_directory(
&self,
path: &Path,
) -> Result<PathBuf, SecurityError>
pub async fn validate_parent_directory( &self, path: &Path, ) -> Result<PathBuf, SecurityError>
Validate parent directory for write operations (TOCTOU-safe)
Sourcepub fn is_rate_limited(&self) -> bool
pub fn is_rate_limited(&self) -> bool
Check if rate limit is exceeded (without recording)
Sourcepub fn record_action(&self) -> usize
pub fn record_action(&self) -> usize
Record an action and return current count
Sourcepub fn try_record_action(&self) -> Result<(), SecurityError>
pub fn try_record_action(&self) -> Result<(), SecurityError>
Try to record an action, returning false if rate limited
This is the main method for checking and recording in one step
Sourcepub fn action_count(&self) -> usize
pub fn action_count(&self) -> usize
Get current action count in the window
Sourcepub fn can_act(&self) -> Result<(), SecurityError>
pub fn can_act(&self) -> Result<(), SecurityError>
Check if can perform an action (rate limit + read-only check)
Sourcepub fn check_file_size(&self, size: u64) -> Result<(), SecurityError>
pub fn check_file_size(&self, size: u64) -> Result<(), SecurityError>
Check if file size is within limits
Trait Implementations§
Source§impl Clone for SecurityPolicy
impl Clone for SecurityPolicy
Source§fn clone(&self) -> SecurityPolicy
fn clone(&self) -> SecurityPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SecurityPolicy
impl Debug for SecurityPolicy
Auto Trait Implementations§
impl !Freeze for SecurityPolicy
impl !RefUnwindSafe for SecurityPolicy
impl Send for SecurityPolicy
impl Sync for SecurityPolicy
impl Unpin for SecurityPolicy
impl UnsafeUnpin for SecurityPolicy
impl UnwindSafe for SecurityPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more