Skip to content

Gemini API key leaks via reqwest error messages returned to proxy users #68

@iBreaker

Description

@iBreaker

Problem

The Gemini adapter embeds the API key directly in the URL query parameter (?key=...) at crates/nyro-core/src/proxy/adapter.rs:92-98:

fn build_url(&self, base_url: &str, path: &str, api_key: &str) -> String {
    let url = format!("{}{path}", base_url.trim_end_matches('/'));
    if url.contains('?') {
        format!("{url}&key={api_key}")
    } else {
        format!("{url}?key={api_key}")
    }
}

When reqwest encounters a connection error, timeout, or DNS failure, its Error Display implementation includes the full request URL. The handler then returns this error to the proxy user via error_response(502, &format!("upstream error: {e}")) (handler.rs lines 764, 907, 1081), leaking the complete Gemini API key.

Exploit scenario

  1. A proxy user sends a request routed to a Gemini provider
  2. The Gemini API is temporarily unreachable (DNS failure, timeout, etc.)
  3. reqwest returns an error like: error sending request for url (https://generativelanguage.googleapis.com/...?key=AIzaSy...)
  4. The full API key is returned to the proxy user in the 502 response

Recommendation

Sanitize error messages before returning to proxy users — strip or redact URLs containing credentials. Alternatively, avoid embedding the key in the URL and use a header-based auth approach for Gemini if supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions