Filter app runtime env vars from terminal spawn environment #44
Merged
juliusmarmingemerged 1 commit into
main fromcodething/2e2908ea·merged by juliusmarminge View on GitHubSummary#
- Filter terminal spawn environment variables to exclude app/runtime keys that can interfere with shell sessions.
- Add explicit exclusion logic for
PORT,ELECTRON_RENDERER_PORT,ELECTRON_RUN_AS_NODE, and any keys prefixed withT3CODE_orVITE_. - Keep unrelated environment variables intact when launching terminal sessions.
- Add a regression test verifying blocked keys are removed and non-blocked keys are preserved.
Testing#
- Not run (not executed in this PR context).
- Added unit test:
apps/server/src/terminalManager.test.ts(filters app runtime env variables from terminal sessions) to verify:PORT,T3CODE_PORT, andVITE_DEV_SERVER_URLare excluded from terminal spawn env.- Non-app variable
TEST_TERMINAL_KEEPis preserved.
Summary by CodeRabbit#
Release Notes#
- Bug Fixes
- Improved terminal environment isolation by filtering out framework and application-specific environment variables from terminal sessions. This prevents potential conflicts and enhances security when spawning new terminal instances.
- 1
Filter terminal spawn environment in
TerminalManager.opento excludePORT,ELECTRON_RENDERER_PORT,ELECTRON_RUN_AS_NODE, and variables starting withT3CODE_orVITE_per the PR motivation in terminalManager.ts#Add terminal env filtering via
TERMINAL_ENV_BLOCKLIST,shouldExcludeTerminalEnvKey, andcreateTerminalSpawnEnv, and updateTerminalManager.opento pass the sanitized env toptyAdapter.spawn. A new test verifies exclusion and retention behavior in terminalManager.test.ts.📍Where to Start#
Start with
TerminalManager.openin terminalManager.ts and trace intocreateTerminalSpawnEnvandshouldExcludeTerminalEnvKey.
Macroscope summarized ecea657.Greptile Overview
Greptile Summary
Adds environment variable filtering to terminal spawn operations to prevent app runtime configuration from interfering with shell sessions.
- Introduces
shouldExcludeTerminalEnvKeyfunction that filters outPORT,ELECTRON_RENDERER_PORT,ELECTRON_RUN_AS_NODE, and variables prefixed withT3CODE_orVITE_ - Adds
createTerminalSpawnEnvhelper that creates a clean environment by excluding filtered keys - Modified
startSessionin apps/server/src/terminalManager.ts:496 to use filtered environment instead ofprocess.envdirectly - Includes regression test with proper environment restoration to verify filtering behavior
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- Clean implementation with focused scope, comprehensive test coverage, and no breaking changes. The filtering logic is straightforward and addresses a specific issue without affecting existing functionality.
- No files require special attention
Important Files Changed
Filename Overview apps/server/src/terminalManager.ts Added environment variable filtering logic to prevent app runtime variables from leaking into terminal sessions. Implementation is clean and well-tested. apps/server/src/terminalManager.test.ts Added comprehensive test verifying that blocked environment variables are excluded while non-app variables are preserved during terminal spawn. Flowchart
Last reviewed commit: ecea657flowchart TD A[startSession called] --> B[createTerminalSpawnEnv called with process.env] B --> C{For each env key/value} C --> D{value === undefined?} D -->|Yes| E[Skip] D -->|No| F{shouldExcludeTerminalEnvKey} F --> G{Starts with T3CODE_?} G -->|Yes| E G -->|No| H{Starts with VITE_?} H -->|Yes| E H -->|No| I{In TERMINAL_ENV_BLOCKLIST?} I -->|Yes - PORT, ELECTRON_RENDERER_PORT, ELECTRON_RUN_AS_NODE| E I -->|No| J[Include in spawnEnv] E --> K{More keys?} J --> K K -->|Yes| C K -->|No| L[Return filtered spawnEnv] L --> M[ptyAdapter.spawn with filtered env]- Introduces
juliusmarminge merged this4b4abcd
juliusmarminge closed this
Sign in to join this conversation.
Walkthrough#
Implements environment variable filtering for spawned terminal sessions. A blocklist of sensitive variables (PORT, ELECTRON_RENDERER_PORT, ELECTRON_RUN_AS_NODE) and framework-specific prefixes (T3CODE_, VITE_) are excluded from the shell environment. New helper functions sanitize the environment before terminal spawn, with comprehensive test coverage validating the filtering behavior.
Changes#
apps/server/src/terminalManager.tsshouldExcludeTerminalEnvKeyandcreateTerminalSpawnEnvhelper functions to filter environment variables. Implemented blocklist for PORT, ELECTRON_RENDERER_PORT, ELECTRON_RUN_AS_NODE and exclusion of variables with T3CODE_ or VITE_ prefixes. Integrated filtered environment into shell spawn withinstartSession.apps/server/src/terminalManager.test.tsEstimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
⚔️
TODO.md(content)⚔️
apps/server/src/terminalManager.test.ts(content)⚔️
apps/server/src/terminalManager.ts(content)⚔️
apps/web/src/components/ChatView.tsx(content)⚔️
apps/web/src/components/Sidebar.tsx(content)These conflicts must be resolved before merging into
main.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
No actionable comments were generated in the recent review. 🎉
🧹 Recent nitpick comments
Comment `@coderabbitai help` to get the list of available commands and usage tips.