refactor: extract shared copyEnvEntries helper to eliminate duplicated env-filtering loops - #6370
Conversation
There was a problem hiding this comment.
Pull request overview
Centralizes environment-variable copying and filtering to reduce duplication and security-policy drift.
Changes:
- Adds configurable
copyEnvEntries. - Migrates four environment-building call sites.
- Adds unit coverage for filters, precedence, callbacks, and size boundaries.
Show a summary per file
| File | Description |
|---|---|
src/env-utils.ts |
Adds the shared filtering helper. |
src/env-utils.test.ts |
Tests helper behavior and option interactions. |
src/sbx-manager.ts |
Uses the helper for secret filtering. |
src/services/agent-environment/env-passthrough.ts |
Uses it for bounded host passthrough. |
src/services/agent-environment/observability-environment.ts |
Uses it for OTEL forwarding. |
src/services/agent-environment/github-actions-environment.ts |
Uses it for env-file and explicit overrides. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Medium
|
@copilot merge main |
…-code-environment-filtering
Done — merged |
|
✅ Copilot review passed with no inline comments. @copilot Add the |
|
✅ Smoke Gemini completed. All facets verified. 💎 |
|
✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟 |
|
✅ Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓 |
|
✅ Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓 |
|
✅ Build Test Suite completed successfully! |
|
🔌 Smoke Services — All services reachable! ✅ |
|
✅ Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓 |
|
🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅ |
|
🚀 Security Guard has started processing this pull request |
|
📰 VERDICT: Smoke Docker Sbx has concluded. All systems operational. This is a developing story. 🎤 |
|
📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅ |
|
✅ Contribution Check completed successfully! PR #6370 follows the contribution guidelines in CONTRIBUTING.md; no comment needed. |
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
Coverage comparison generated by |
Smoke Test: Claude Engine Validation
Overall Result: PASS Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
🔬 Smoke Test Results
Overall: PASS (core connectivity verified) Author: Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
Smoke Test: Copilot BYOK (Direct) Mode ✅ PASS
Running in direct BYOK mode via COPILOT_PROVIDER_API_KEY path. Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
|
🔒 Smoke Test: Copilot Network Isolation Egress — EGRESS_RESULT allow=pass deny=pass
Overall: PASS Warning Firewall blocked 2 domainsThe following domains were blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"
- "example.com"See Network Configuration for more information.
|
Smoke Test: Copilot PAT Auth
Overall: PARTIAL — template expressions were not expanded at runtime. MCP reachable. Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
Smoke Test Results
PRs Reviewed:
Overall status: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
Smoke Test: Services Connectivity
Overall: FAIL
Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
|
Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra Overall: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
|
PR: refactor: extract shared copyEnvEntries helper to eliminate duplicated env-filtering loops Checks:
Overall: PASS Warning Firewall blocked 2 domainsThe following domains were blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"
- "registry.npmjs.org"See Network Configuration for more information.
|
Chroot Version Comparison Results
Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
🔬 OTEL Tracing Smoke Test Results
All 5 scenarios pass. OTEL tracing integration is fully functional. Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
|
GitHub MCP Testing: ✅ Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) Overall: PASS Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
🔥 Smoke Test: Docker Sbx Validation
Overall Status: INCONCLUSIVE — GitHub Actions template variables (
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
Four files each re-implemented a nearly identical
for...of Object.entries()loop to copy/filter environment variables into a target object, with slightly different allow/deny rules. Drift in this security-sensitive isolation code is risky.Changes
src/env-utils.ts— newcopyEnvEntries(source, target, options)helper covering all four call-site variants:excludedKeys/allowKeys— set-based deny with selective override (proxy var passthrough)noOverwrite— skip keys already present in targetkeyPredicate— arbitrary key filter (OTEL_ prefix, secret-pattern negation)maxValueSizeBytes+onSkippedOversized— size cap with callback for--env-allpassthroughenv-passthrough.ts,observability-environment.ts,github-actions-environment.ts,sbx-manager.ts— each inline loop replaced with acopyEnvEntriescallsrc/env-utils.test.ts— 10 new tests covering each option and their interactions