Use public container IP in managed agent prompts#203
Conversation
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThis PR detects the Docker-Git container's public IPv4 address at startup and injects public IP guidance into Claude, Codex, and Gemini agent prompts. The public IP is discovered via override, ChangesDocker-Git Public IP Detection and Agent Integration
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/lib/src/core/templates-entrypoint/base.ts`:
- Around line 95-99: The candidate IP selection and serialization logic should
validate IPv4 addresses and safely escape before persisting: restrict the
hostname -I awk filter to only emit IPv4 tokens (e.g., match
/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) so candidate only becomes an IPv4, then
after detection add an explicit IPv4 format check on the candidate variable
before accepting it; finally, when printing/serializing DOCKER_GIT_PUBLIC_IP for
writing into shell startup files, use a shell-escaping safe formatter (replace
printf "%s" "$candidate" with a quoted/escaped form, e.g., using printf "%q" or
equivalent) so the value is safely escaped when sourced. Ensure changes
reference the candidate variable, the hostname -I | awk filter, and the printf
serialization call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 15f28693-b092-4816-bb34-688354955c62
📒 Files selected for processing (6)
packages/app/tests/docker-git/entrypoint-auth.test.tspackages/lib/src/core/templates-entrypoint.tspackages/lib/src/core/templates-entrypoint/base.tspackages/lib/src/core/templates-entrypoint/claude-extra-config.tspackages/lib/src/core/templates-entrypoint/codex.tspackages/lib/src/core/templates-entrypoint/gemini.ts
| if [[ -z "$candidate" ]] && command -v hostname >/dev/null 2>&1; then | ||
| candidate="$(hostname -I 2>/dev/null | awk '{for (i = 1; i <= NF; i += 1) if ($i != "127.0.0.1") { print $i; exit }}')" | ||
| fi | ||
|
|
||
| printf "%s" "$candidate" |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify current unsafe serialization and weak fallback filtering in the reviewed file.
rg -n 'hostname -I' packages/lib/src/core/templates-entrypoint/base.ts
rg -n 'export DOCKER_GIT_PUBLIC_IP="\$DOCKER_GIT_PUBLIC_IP"' packages/lib/src/core/templates-entrypoint/base.ts
rg -n '^[[:space:]]*local ipv4_regex=|~ /\\^\\[0-9\\]\\+' packages/lib/src/core/templates-entrypoint/base.tsRepository: ProverCoderAI/docker-git
Length of output: 251
🏁 Script executed:
cat -n packages/lib/src/core/templates-entrypoint/base.ts | head -130 | tail -60Repository: ProverCoderAI/docker-git
Length of output: 2786
Validate and safely serialize DOCKER_GIT_PUBLIC_IP before persisting it to shell startup files.
Line 96 can accept non-IPv4 tokens from hostname -I, and line 107 interpolates the value directly into a sourced shell script without format validation. A non-IPv4 address (IPv6 or other token) violates expected IP format and can break downstream service URL construction.
The fix adds IPv4 format validation in the awk filter and post-detection check, then uses printf %q for safe escaping during serialization.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/lib/src/core/templates-entrypoint/base.ts` around lines 95 - 99, The
candidate IP selection and serialization logic should validate IPv4 addresses
and safely escape before persisting: restrict the hostname -I awk filter to only
emit IPv4 tokens (e.g., match /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) so candidate
only becomes an IPv4, then after detection add an explicit IPv4 format check on
the candidate variable before accepting it; finally, when printing/serializing
DOCKER_GIT_PUBLIC_IP for writing into shell startup files, use a shell-escaping
safe formatter (replace printf "%s" "$candidate" with a quoted/escaped form,
e.g., using printf "%q" or equivalent) so the value is safely escaped when
sourced. Ensure changes reference the candidate variable, the hostname -I | awk
filter, and the printf serialization call.
Summary
Testing
Closes #78.