Skip to content

fxmacrodata: send the API key as a header, not a query parameter - #51

Open
roberttidball wants to merge 1 commit into
ml4t:mainfrom
roberttidball:fxmacrodata-header-auth
Open

fxmacrodata: send the API key as a header, not a query parameter#51
roberttidball wants to merge 1 commit into
ml4t:mainfrom
roberttidball:fxmacrodata-header-auth

Conversation

@roberttidball

Copy link
Copy Markdown

The FXMacroData provider appends the API key to the query string:

if self.api_key:
    clean_params["api_key"] = self.api_key

FXMacroData accepts the key three ways and its OpenAPI spec documents X-API-Key as the preferred transport for server-side clients, precisely because a key in the query string is written verbatim into every proxy, CDN and server access log along the request path, and into any local HTTP debug output. The other keyed providers in this repo are unaffected; each has its own _request_json.

This switches to a per-request header, so the behaviour still tracks self.api_key rather than freezing it into the session at construction, and no auth header is sent at all when no key is configured.

Tests: the existing request test now asserts the header and the absence of an api_key parameter, plus two new ones - that no parameter value carries the key, and that no auth header is sent without a key. The keyless test clears the environment, since otherwise an ambient FXMACRODATA_API_KEY would be picked up and the assertion would pass for the wrong reason.

Checks: pytest tests/test_fxmacrodata_provider.py 23 passed, ruff check, ruff format --check and ty check all clean.

Disclosure: I work on FXMacroData. Thanks for building the provider - this is only about how the key is transported, nothing about the data.

🤖 Generated with Claude Code

FXMacroData accepts the key three ways and documents X-API-Key as the preferred
transport for server-side clients. The provider was appending it to the query
string instead, so the key was written verbatim into every proxy, CDN and server
access log along the request path, and into any local HTTP debug output.

Switch to a per-request header so the behaviour still tracks self.api_key rather
than freezing it into the session at construction, and leave headers unset
entirely when no key is configured.

Covered by three tests: the existing request test now asserts the header and the
absence of an api_key parameter, plus one that no parameter value carries the key
and one that no auth header is sent without a key. The keyless test clears the
environment, since otherwise an ambient FXMACRODATA_API_KEY would be picked up
and the assertion would pass for the wrong reason.

Co-Authored-By: Claude Opus 5 <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