T09 · Insecure Skill Coding Practices
- Location
zotero_search.py:41- Finding
Arbitrary Local API Endpoint Can Receive Zotero Credentials
- Content
View full analysis
Vulnerability Details
File Location:
zotero_search.py:41-70,zotero_search.py:196-197, andzotero_search.py:215-216
Vulnerability Type: Credential disclosure through an unrestricted network destination
Risk Level: HighVulnerable Code
python def get_local_api_key(): """From configuration file to get Zotero local API key""" config_path = Path.home() / '.config' / 'zotero' / 'local_api_key' if config_path.exists(): with open(config_path, 'r', encoding='utf-8') as f: return f.read().strip() # Fall back to the general API key return get_api_key() def search_local(query, limit=10, base_url='http://localhost:23119/api'): """Search using the Zotero local API""" search_url = f"{base_url}/3/items" params = { 'q': query, 'limit': limit, 'format': 'json' } api_key = get_local_api_key() headers = {} if api_key: headers['Authorization'] = f'Bearer {api_key}' try: response = requests.get( search_url, params=params, headers=headers, timeout=5 )python parser.add_argument( '--api-url', type=str, default='http://localhost:23119/api', help='Local API address' )python if args.local: print(f"API address: {args.api_url}") items = search_local(args.query or '', args.limit, args.api_url)Technical Analysis
The
--api-urlargument is accepted without validating its scheme, hostname, port, or resolved address.search_local()then constructs a request from that value and attaches a Zotero credential as anAuthorization: Bearerheader.The credential selection increases the exposure: if a dedicated local API key does not exist,
get_local_api_key()falls back to the remote Zotero API key. Consequently, a command presented as a local sea ...[truncated 1653 chars]- Remediation
View remediation
Remediation Suggestions
- Restrict local API destinations to explicit loopback addresses:
localhost127.0.0.1[::1]
- Resolve the hostname and verify that every resolved address is loopback before sending credentials.
- Allow only plain HTTP to a verified loopback destination, unless a separately trusted local TLS configuration is implemented.
- Disable automatic redirects or revalidate every redirect destination before forwarding credentials:
python requests.get(..., allow_redirects=False) - Never fall back from the local API key to the remote Zotero API key.
- Do not attach authentication unless a dedicated local token was explicitly configured.
- If custom ports are required, permit a validated numeric port while keeping the hostname fixed to loopback.
- Add tests confirming that external, private-network, malformed, and redirecting URLs are rejected.
- Restrict local API destinations to explicit loopback addresses:
