feat(security): add auth middleware, SSRF protection, shell hardening, and encrypted secrets#117
Merged
jamiepine merged 1 commit intospacedriveapp:mainfrom Feb 22, 2026
Conversation
…, and encrypted secrets Implement 6 security fixes identified during codebase audit: - API authentication middleware with Bearer token validation, exempting health check endpoints - Webhook authentication via Authorization header or X-Webhook-Token, with startup warning when unconfigured - Browser SSRF protection blocking private/loopback IPs, link-local, CGNAT ranges, and cloud metadata endpoints (169.254.169.254) - Shell command hardening blocking backtick/$() subshell execution, eval/exec builtins, /dev/fd access, and env dump commands - Cron job input validation enforcing minimum 60s intervals, prompt length limits, and delivery target format checks - Secrets store rewrite with AES-256-GCM encryption, SHA-256 key derivation, random nonces, and DecryptedSecret wrapper with redacted Debug/Display
Member
|
absolutely amazing |
jamiepine
approved these changes
Feb 22, 2026
ivanhoe
pushed a commit
to ivanhoe/spacebot
that referenced
this pull request
Feb 22, 2026
- Add url = "2" to Cargo.toml (browser.rs uses url::Url::parse but crate was missing) - Fix api_auth_middleware to use State<Arc<ApiState>> extractor (required by axum 0.8's from_fn_with_state) These errors prevent clean compilation on main since PR spacedriveapp#117 merge.
sra
added a commit
to sra/spacebot
that referenced
this pull request
Feb 22, 2026
…d TLS Fixes several Slack adapter issues and restores the build after spacedriveapp#117. Build fixes: - Restore compile after security middleware changes (Axum State extractor pattern in api_auth_middleware, url::Url → reqwest::Url in browser tool) (this is from unmerged pr spacedriveapp#125) Slack DM filtering: - DMs now bypass workspace/channel filters when sender is in dm_allowed_users - dm_allowed_users is merged from both SlackConfig and per-binding configs - Added debug logging for DM permission decisions Emoji reactions: - Sanitize Slack emoji reactions to use shortcodes via the `emojis` crate - Handle edge case where emoji has no shortcode (falls back to name) - Strip colons, normalize whitespace and casing TLS connectivity: - Add tokio-tungstenite with rustls-tls-native-roots feature to fix wss:// connections that broke after the tungstenite 0.28 TLS feature restructure Logging: - Downgrade per-message Slack log from info to debug, matching Discord, Telegram, and Twitch adapters which only use info for lifecycle events Style: - Rename abbreviated `uid` to `sender_id` per style guide - Remove section-divider comments and extra blank lines in imports Tests: - 9 unit tests for sanitize_reaction_name (unicode, shortcodes, fallbacks) - 7 unit tests for SlackPermissions::from_config (merging, dedup, filtering)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements 6 security fixes identified during a comprehensive codebase audit. All changes are additive and backward-compatible — existing deployments without auth tokens configured will continue to work with warning logs.
10 files changed, 510 insertions, 23 deletions.
Changes
1. API Authentication Middleware (Critical)
Files:
src/api/server.rs,src/api/state.rs,src/config.rs,src/main.rs/api/health,/health) are exemptedapi.auth_tokenin config (supportsenv:VAR_NAMEresolution)2. Webhook Authentication (Critical)
Files:
src/messaging/webhook.rs,src/config.rs,src/main.rs,src/api/messaging.rshandle_sendandhandle_pollendpointsAuthorization: Bearer <token>andX-Webhook-Tokenheaderswebhook.auth_tokenin config (supportsenv:VAR_NAMEresolution)3. Secrets Store (Critical)
Files:
src/secrets/store.rsDecryptedSecretwrapper with redactedDebugandDisplayimplsnew(),set(),get(),delete(),list()4. Browser SSRF Protection (Critical)
Files:
src/tools/browser.rsvalidate_url()blocking navigation to internal networks169.254.169.254,metadata.google.internalhandle_navigate()andhandle_open()5. Shell Command Hardening (High)
Files:
src/tools/shell.rs$(...),<(...),>(...)subshell execution patternsevalandexecbuiltins via pipeline-awarecontains_shell_builtin()helper/dev/fd/and/dev/stdinaccessset,declare -p,compgen,export6. Cron Job Input Validation (High)
Files:
src/tools/cron.rsMIN_CRON_INTERVAL_SECS)MAX_CRON_PROMPT_LENGTH)Testing
cargo buildnot run due to missingprotocsystem dependency (LanceDB)Configuration
New optional config fields (all backward-compatible):