Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyrit/prompt_target/http_target/http_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ def _infer_full_url_from_host(
headers_dict: dict[str, str],
) -> str:
# If path is already a full URL, return it as is
path = path.lower()
if path.startswith(("http://", "https://")):
return path

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/target/test_http_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ def test_parse_raw_http_request_ignores_content_length(patch_central_database):

def test_parse_raw_http_respects_url_path(patch_central_database):
request1 = (
"POST https://diffsite.com/test/ HTTP/1.1\nHost: example.com\nContent-Type: "
"POST https://diffsite.com/Test/Path?Token=AbC123 HTTP/1.1\nHost: example.com\nContent-Type: "
"application/json\nContent-Length: 100\n\n"
)
target = HTTPTarget(http_request=request1)
headers, _, url, _, _ = target.parse_raw_http_request(request1)
assert url == "https://diffsite.com/test/"
assert url == "https://diffsite.com/Test/Path?Token=AbC123"

# The host header should still be example.com
assert headers == {"host": "example.com", "content-type": "application/json"}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/target/test_http_target_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ def test_parse_raw_http_request(mock_http_target):
assert version == "HTTP/1.1"


def test_parse_raw_http_request_preserves_relative_url_case(sqlite_instance):
request = "GET /CaseSensitive/Run?token=AbC123&Mode=Keep HTTP/1.1\nHost: Example.COM\n\n"
target = HTTPTarget(http_request=request)

_, _, url, method, version = target.parse_raw_http_request(request)

assert url == "https://Example.COM/CaseSensitive/Run?token=AbC123&Mode=Keep"
assert method == "GET"
assert version == "HTTP/1.1"


def test_parse_regex_response_no_match():
mock_response = MagicMock()
mock_response.content = b"<html><body>No match here</body></html>"
Expand Down
Loading