Skip to content

Conversation

@ldemesla
Copy link
Contributor

Problem

Fixed a critical bug in extract_host_port() that caused malformed URLs like http://http://localhost:3000 when the target already contained a protocol scheme.

The extract_host_port() function was using naive string splitting on : which incorrectly parsed URLs:

Example of the bug:

  • Input: http://localhost:3000
  • Old behavior: Returns ("http://localhost", 3000)
  • URL reconstruction: f"http://{host}:{port}/login"
  • Result: http://http://localhost:3000/login
  • Error: getaddrinfo ENOTFOUND http

This manifested on macOS (and potentially Linux) as DNS resolution errors when the agent attempted HTTP requests.

Solution

Rewrote extract_host_port() to use urllib.parse.urlparse which properly handles URL parsing:

  • Input: http://localhost:3000
  • New behavior: Returns ("localhost", 3000)
  • URL reconstruction: f"http://{host}:{port}/login"
  • Result: http://localhost:3000/login

Changes

  • Fixed extract_host_port() in http_parser.py to use urlparse
  • Added comprehensive unit tests (15 tests, all passing)
  • Verified fix with Juice Shop server on localhost:3000

Testing

uv run pytest deadend_agent/tests/deadend_sdk/tools/browser_automation/test_extract_host_port.py -v

All 15 tests pass, including critical test for protocol duplication prevention.

Impact

This fix resolves the issue where agents running on macOS (and potentially Linux) were unable to perform HTTP requests due to malformed URLs.

🤖 Generated with Claude Code

…rors

Fixed a critical bug in extract_host_port() that caused malformed URLs
like "http://http://localhost:3000" when the target already contained
a protocol scheme.

## Problem
The extract_host_port() function used naive string splitting on ':'
which incorrectly parsed URLs containing protocol schemes:
- Input: "http://localhost:3000"
- Old output: ("http://localhost", 3000)
- URL construction: f"http://{host}:{port}/login"
- Result: "http://http://localhost:3000/login" ❌
- Error: getaddrinfo ENOTFOUND http

This manifested on macOS (and potentially Linux) as DNS resolution
errors when the agent attempted HTTP requests.

## Solution
Rewrote extract_host_port() to use urllib.parse.urlparse which
properly handles URL parsing:
- Input: "http://localhost:3000"
- New output: ("localhost", 3000)
- URL construction: f"http://{host}:{port}/login"
- Result: "http://localhost:3000/login" ✅

## Changes
- Fixed extract_host_port() in http_parser.py to use urlparse
- Added comprehensive unit tests (15 tests, all passing)
- Verified fix with Juice Shop server on localhost:3000

## Testing
All tests pass including critical test for protocol duplication prevention.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant