Skip to content

PageSpeed: keep the API key out of connection errors - #151

Open
HeyImBG wants to merge 1 commit into
kLOsk:mainfrom
HeyImBG:fix/pagespeed-key-leak
Open

HeyImBG wants to merge 1 commit into
kLOsk:mainfrom
HeyImBG:fix/pagespeed-key-leak

Conversation

@HeyImBG

@HeyImBG HeyImBG commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

analyze_page_speed sends pagespeed.api_key as the key query parameter. When the request fails before a response (offline, DNS, refused connection), requests quotes the full URL in its exception text, e.g. Max retries exceeded with url: /...runPagespeed?url=...&key=<the key>. The _safe wrapper returns that text as the tool error, so the key lands in the model's context and the chat transcript.

This catches requests.RequestException in analyze_page_speed, replaces the key with [redacted] and returns PageSpeed API request failed (<ExceptionName>): .... It also means a network failure now returns a normal error dict instead of a bare exception.

Tests: two new tests in tests/test_pagespeed.py that hit a closed local port, so the exception is the real one from requests. Without the fix both tests error out with the raw ConnectionError, whose text contains key=test-key. Full suite: 2772 passed, 2 skipped.

This is not a write tool, so the safety layer is untouched.

Found, written and tested with Claude Code; I'm responsible for it.

requests quotes the full request URL, query string included, in its
connection errors. analyze_page_speed sends the API key in that query, so
an unreachable network or a refused connection returned the key in the
tool error, where the model and the chat transcript see it.

Catch requests.RequestException, redact the key and report the failure.

This branch has not been deployed

No deployments
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