Skip to content

feat: add localhost keyword for playwright testing#427

Merged
Mossaka merged 10 commits intomainfrom
copilot/setup-playwright-testing
Feb 4, 2026
Merged

feat: add localhost keyword for playwright testing#427
Mossaka merged 10 commits intomainfrom
copilot/setup-playwright-testing

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

Playwright tests against local dev servers required manual configuration of host access, domain mapping, and port allowlists. The localhost keyword now auto-configures this setup.

Changes

CLI Enhancement (src/cli.ts)

  • localhost in --allow-domains automatically:
    • Maps to host.docker.internal (preserves http:// / https:// prefixes)
    • Enables --enable-host-access
    • Allows common dev ports: 3000, 3001, 4000, 4200, 5000, 5173, 8000, 8080, 8081, 8888, 9000, 9090
    • User override via --allow-host-ports still respected

Container Fix (containers/agent/setup-iptables.sh)

  • Removed multiport module from port range rules (not supported by iptables DNAT)

Testing (tests/integration/localhost-access.test.ts)

  • 8 test cases covering auto-enable, protocol prefixes, custom ports, host resolution

Documentation

  • Added Playwright guide to docs-site
  • Updated README, usage docs, and AGENTS.md

Usage

# Before
sudo awf \
  --enable-host-access \
  --allow-domains host.docker.internal \
  --allow-host-ports 3000,8080 \
  -- npx playwright test

# After
sudo awf --allow-domains localhost,playwright.dev -- npx playwright test

Security warnings maintained for host access. Custom port lists still supported via --allow-host-ports.

Original prompt

This section details on the original issue you should resolve

<issue_title>Playwright testing</issue_title>
<issue_description>Texting a localhost web site should work out of the box.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 26, 2026 21:16
- Automatically maps 'localhost' to 'host.docker.internal'
- Enables host access when localhost is specified
- Configures common development ports (3000, 4200, 5173, 8080, etc.)
- Supports protocol prefixes (http://localhost, https://localhost)
- Preserves user-specified --allow-host-ports if provided
- Add comprehensive integration tests for localhost functionality

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
- Add localhost keyword section to AGENTS.md
- Add Playwright testing examples to README.md
- Add comprehensive guide to docs/usage.md
- Create dedicated Playwright testing guide in docs-site
- Explain automatic configuration and security considerations

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Add localhost to --allow-domains help text explaining it auto-configures for local testing

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Playwright testing for localhost web site feat: add localhost keyword for playwright testing Jan 26, 2026
Copilot AI requested a review from Mossaka January 26, 2026 21:21
@Mossaka Mossaka marked this pull request as ready for review January 26, 2026 23:07
@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions
Copy link
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 77.98% 77.23% 📉 -0.75%
Statements 78.05% 77.32% 📉 -0.73%
Functions 77.77% 77.36% 📉 -0.41%
Branches 71.70% 70.64% 📉 -1.06%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/cli.ts 40.1% → 37.8% (-2.24%) 40.3% → 38.0% (-2.24%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions
Copy link
Contributor

Smoke Test Results

Last 2 merged PRs:

✅ GitHub MCP
✅ Playwright (title: "GitHub · Change is constant. GitHub keeps you ahead. · GitHub")
✅ File writing
✅ Bash tool

Status: PASS

cc @copilot @Mossaka

AI generated by Smoke Copilot

@github-actions
Copy link
Contributor

Smoke Test Results (Claude Engine)

GitHub MCP:

Tests:
✅ GitHub MCP - Retrieved last 2 merged PRs
✅ Playwright - Verified page title "GitHub · Change is constant. GitHub keeps you ahead. · GitHub"
✅ File Writing - Created /tmp/gh-aw/agent/smoke-test-claude-21374333874.txt
✅ Bash Tool - Verified file contents

Status: PASS

AI generated by Smoke Claude

@github-actions
Copy link
Contributor

Security Review: Localhost Keyword Feature

I've reviewed PR #427 for security implications. The implementation is generally sound with proper validation, but I found one security concern that should be addressed before merge.


🔴 Security Issue: Port 8888 in Default Port List

File: src/cli.ts (line 665)

Issue: The default localhost port list includes port 8888, which is commonly used by Jupyter Notebook/JupyterLab servers:

options.allowHostPorts = '3000,3001,4000,4200,5000,5173,8000,8080,8081,8888,9000,9090';

Security Risk:

  • Jupyter servers provide arbitrary code execution capabilities via notebooks
  • If a user has a Jupyter server running on their host machine while using the firewall, the localhost keyword would automatically grant AI agents access to it
  • This creates an unintended privilege escalation path where an agent could execute Python code on the host

Recommendation:

  1. Remove port 8888 from the default list, OR
  2. Add port 8888 to DANGEROUS_PORTS constant in src/squid-config.ts to block it entirely

Suggested fix:

// Remove 8888 from this line:
options.allowHostPorts = '3000,3001,4000,4200,5000,5173,8000,8080,8081,9000,9090';

Users who genuinely need Jupyter access can explicitly specify --allow-host-ports 8888 with full awareness of the security implications.


✅ Security Aspects That Are Safe

  1. Port validation works correctly - All ports go through the existing DANGEROUS_PORTS check in squid-config.ts which blocks SSH (22), databases (3306, 5432, etc.), and other sensitive services

  2. iptables bug fix is legitimate - The removal of -m multiport from DNAT rules (line 177 in setup-iptables.sh) is a valid fix since multiport doesn't support port ranges in DNAT context

  3. Protocol preservation - HTTP/HTTPS prefixes are correctly preserved when mapping localhost to host.docker.internal

  4. User override capability - Users can still customize with --allow-host-ports to override defaults

  5. Host access intentional - The automatic enablement of --enable-host-access is documented with appropriate security warnings


Verdict

Conditional approval - Safe to merge after removing port 8888 from the default list. All other aspects of the implementation maintain the firewall's security posture.

AI generated by Security Guard

@Mossaka
Copy link
Collaborator

Mossaka commented Feb 3, 2026

@copilot please merge origin/main

@Mossaka
Copy link
Collaborator

Mossaka commented Feb 3, 2026

@copilot merge main and bump up the test coverage so https://github.com/github/gh-aw-firewall/actions/runs/21374333813/job/61536955621?pr=427 won't fail

Copilot and others added 2 commits February 3, 2026 19:59
Extract localhost processing logic into testable function and add comprehensive unit tests covering:
- Plain localhost, http://localhost, https://localhost variants
- Protocol prefix preservation
- Host access auto-enablement
- Default port configuration
- Edge cases and domain order preservation

Coverage improvements:
- Overall: 81.58% → 82.03% (+0.45%)
- cli.ts lines: 37.82% → 41.47% (+3.65%)
- cli.ts branches: 31.03% → 38.01% (+6.98%)

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copy link
Collaborator

@Mossaka Mossaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: REQUEST_CHANGES

@copilot Please fix the following security issue:

Issue: Missing Security Warning

When the localhost keyword auto-enables --enable-host-access, there should be a security warning. Currently, users may not realize they've exposed their host machine to the agent.

Required Fix

Add a security warning in src/cli.ts when localhost triggers host access:

if (localhostResult.shouldEnableHostAccess) {
  options.enableHostAccess = true;
  logger.warn('Security warning: localhost keyword enables host access - agent can reach services on your machine');
  logger.info('localhost keyword detected - automatically enabling host access');
}

Additional Suggestions

  1. Handle multiple localhost variants consistently (e.g., if both localhost and http://localhost are specified)
  2. Add an integration test verifying dangerous ports (SSH:22, databases) are still blocked when using localhost keyword
  3. Consider reducing the default port list to truly common dev ports (3000, 5173, 8080) and require explicit --allow-host-ports for others

The feature is well-implemented otherwise - just needs the security warning.

Copilot AI and others added 4 commits February 4, 2026 17:17
# Conflicts:
#	src/cli.test.ts
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 82.44% 82.08% 📉 -0.36%
Statements 82.47% 82.12% 📉 -0.35%
Functions 81.77% 81.95% 📈 +0.18%
Branches 75.59% 75.41% 📉 -0.18%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/cli.ts 40.5% → 41.7% (+1.22%) 40.7% → 41.9% (+1.20%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Smoke Test Results

Last 2 Merged PRs:

Test Results:
✅ GitHub MCP Testing
✅ Playwright Testing (title: "GitHub · Change is constant. GitHub keeps you ahead. · GitHub")
✅ File Writing Testing
✅ Bash Tool Testing

Overall Status: PASS

cc @Mossaka

AI generated by Smoke Copilot

@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Smoke Test Results - Claude Engine

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP: Retrieved PR data
  • ✅ Playwright: Navigated to GitHub, title verified
  • ✅ File Write: Created test file successfully
  • ✅ Bash: Verified file contents

Status: PASS

AI generated by Smoke Claude

@Mossaka Mossaka merged commit 1c50236 into main Feb 4, 2026
45 of 47 checks passed
@Mossaka Mossaka deleted the copilot/setup-playwright-testing branch February 4, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playwright testing

2 participants