-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add github copilot api proxy support #945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d8be285
a1ed818
2de280c
d563021
1fa603d
5d0c17e
ea5b8f6
06459c6
e2fc2fb
47f5a75
1a3b742
1df8d2b
f99e45a
6bf49ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,52 @@ | ||
| #!/bin/bash | ||
| # Example: Using GitHub Copilot CLI with the firewall | ||
| # Example: Using GitHub Copilot CLI with the firewall and API proxy | ||
| # | ||
| # This example shows how to run GitHub Copilot CLI through the firewall. | ||
| # Copilot requires access to several GitHub domains. | ||
| # This example shows how to run GitHub Copilot CLI through the firewall | ||
| # with credential isolation via the API proxy sidecar. | ||
| # | ||
| # Prerequisites: | ||
| # - GitHub Copilot CLI installed: npm install -g @github/copilot | ||
| # - GITHUB_TOKEN environment variable set | ||
| # - COPILOT_API_KEY environment variable set (for API proxy) | ||
|
||
| # - GITHUB_TOKEN environment variable set (for GitHub API access) | ||
| # | ||
| # Usage: sudo -E ./examples/github-copilot.sh | ||
|
|
||
| set -e | ||
|
|
||
| echo "=== AWF GitHub Copilot CLI Example ===" | ||
| echo "=== AWF GitHub Copilot CLI Example (with API Proxy) ===" | ||
| echo "" | ||
|
|
||
| # Check for COPILOT_API_KEY | ||
| if [ -z "$COPILOT_API_KEY" ]; then | ||
| echo "Error: COPILOT_API_KEY environment variable is not set" | ||
| echo "Set it with: export COPILOT_API_KEY='your_copilot_api_key'" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check for GITHUB_TOKEN | ||
| if [ -z "$GITHUB_TOKEN" ]; then | ||
| echo "Error: GITHUB_TOKEN environment variable is not set" | ||
| echo "Set it with: export GITHUB_TOKEN='your_token'" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Running GitHub Copilot CLI through the firewall..." | ||
| # Enable one-shot-token debug logging | ||
| export AWF_ONE_SHOT_TOKEN_DEBUG=1 | ||
|
|
||
| echo "Running GitHub Copilot CLI with API proxy and debug logging enabled..." | ||
| echo "" | ||
|
|
||
| # Run Copilot CLI with required domains | ||
| # Use sudo -E to preserve environment variables (especially GITHUB_TOKEN) | ||
| # Run Copilot CLI with API proxy enabled | ||
| # Use sudo -E to preserve environment variables (COPILOT_GITHUB_TOKEN, GITHUB_TOKEN, AWF_ONE_SHOT_TOKEN_DEBUG) | ||
| # Required domains: | ||
| # - api.githubcopilot.com: Copilot API endpoint (proxied via api-proxy) | ||
| # - github.com: GitHub API access | ||
| # - api.github.com: GitHub REST API | ||
| # - api.enterprise.githubcopilot.com: Copilot API endpoint | ||
| # - registry.npmjs.org: NPM package registry (for npx) | ||
| sudo -E awf \ | ||
| --allow-domains github.com,api.github.com,api.enterprise.githubcopilot.com,registry.npmjs.org \ | ||
| --enable-api-proxy \ | ||
| --allow-domains api.githubcopilot.com,github.com,api.github.com,registry.npmjs.org \ | ||
| --log-level debug \ | ||
| -- 'npx @github/copilot --prompt "What is 2+2?" --no-mcp' | ||
|
|
||
| echo "" | ||
|
|
||
Check warning
Code scanning / CodeQL
Log injection Medium
Copilot Autofix
AI 5 days ago
To fix the problem in general, user-controlled values should only be written to logs after being passed through a clear, robust sanitization step that (a) strips or encodes control characters (especially
\rand\n), (b) limits length, and (c) makes it obvious in the log line where user input begins and ends. The logger call should never insert raw, unsanitized request data.In this specific file, most of that is already done via
sanitizeForLog. The minimal, non‑functional change that addresses the concern is to: (1) ensuresanitizeForLogbehaves safely even for non‑string inputs (e.g.,undefined, objects) by converting them to strings before sanitizing, and (2) slightly adjust the log message on line 250 so that user-supplied fields are clearly marked (e.g.,method="..." url="...") and continue to go throughsanitizeForLog. This keeps all existing behavior (still logs method and URL, same truncation/character stripping) while making the sanitization more robust and explicit.Concretely:
containers/api-proxy/server.js, updatesanitizeForLogso it stringifies non‑string inputs instead of returning an empty string, then strips control characters and truncates as before.sanitizeForLog(req.method)andsanitizeForLog(req.url)but change the template string on line 250 to clearly delineate user content, e.g.,[Copilot Proxy] method="${...}" url="${...}". This preserves functionality while clarifying intent and improving readability/security posture.No new imports or external methods are required; we reuse built‑in string manipulation.