T05 · Unauthorized Access and Privilege Escalation
- Location
src/baidu_search/main.py:44- Finding
Unauthenticated Search Endpoint Can Be Exposed on All Network Interfaces
- Content
View full analysis
Vulnerability Details
File Location:
src/baidu_search/main.py:44-59
Vulnerability Type: Missing authentication and unsafe default network exposure
Risk Level: MediumVulnerable Code
python @app.post("/search", response_model=SearchResponse) def web_search(request: SearchRequest) -> SearchResponse: return search(request) if __name__ == "__main__": import uvicorn uvicorn.run("baidu_search.main:app", host="0.0.0.0", port=8001)Technical Analysis
The
/searchendpoint performs upstream requests using the server-sideBAIDU_API_KEY, but it does not require authentication or authorization. When the module is executed directly, Uvicorn binds to0.0.0.0, making the endpoint available through every configured network interface unless an external firewall prevents access.This differs from the documented command that binds the service to
127.0.0.1. Consequently, an operator who launches the module directly may unintentionally expose a credential-backed API proxy to other hosts. Attackers do not obtain the API key itself, but they can cause the application to use it on their behalf.Attack Path
- An operator configures a valid
BAIDU_API_KEY. - The operator starts the service by executing
baidu_search.maindirectly. - Uvicorn listens on
0.0.0.0:8001. - An attacker with network access identifies the exposed port.
- The attacker repeatedly sends valid JSON requests to
/search. - The service authenticates each upstream request with the operator's Baidu API key.
- The attacker consumes the account's API quota and associated resources without possessing the key.
Impact Assessment
A remote network-accessible attacker can submit arbitrary searches under the operator's Baidu account and consume its quota or incur usage costs. Repeated requests may also exhaust application workers or upstream capacity, causing denial of service for legitimate users.
...[truncated 184 chars]
- An operator configures a valid
- Remediation
View remediation
Remediation Suggestions
- Change the direct-execution default to loopback-only binding:
python uvicorn.run("baidu_search.main:app", host="127.0.0.1", port=8001) - Require authentication for
/searchif remote access is necessary. Use a securely generated service credential, OAuth2, or authentication enforced by a trusted reverse proxy. - Add per-client and global rate limits to prevent quota abuse and resource exhaustion.
- Restrict network access with firewall rules or private-network controls.
- Apply request quotas and monitor unusual request volumes and upstream consumption.
- Document that public exposure requires TLS, authentication, authorization, and rate limiting.
- Change the direct-execution default to loopback-only binding:
