T09 · Insecure Skill Coding Practices
- Location
scripts/setup_webhook.py:147- Finding
Unauthenticated webhook receiver exposes sensitive email payloads
- Content
View full analysis
Vulnerability Details
File Location:
scripts/setup_webhook.py:147-175
Vulnerability Type: Unauthenticated network endpoint and sensitive-data logging
Risk Level: MediumVulnerable Code
python @app.route('/webhook', methods=['POST']) def webhook(): payload = request.json print("\n🪝 Webhook received:") print(f" Event: {payload.get('event_type')}") print(f" ID: {payload.get('event_id')}") if payload.get('event_type') == 'message.received': message = payload.get('message', {}) print(f" From: {message.get('from', [{}])[0].get('email')}") print(f" Subject: {message.get('subject')}") print(f" Preview: {message.get('preview', '')[:50]}...") print(f" Full payload: {json.dumps(payload, indent=2)}") print() return Response(status=200) print("🚀 Starting webhook test server on http://localhost:3000") print("📡 Webhook endpoint: http://localhost:3000/webhook") print("\n💡 For external access, use ngrok:") print(" ngrok http 3000") print("\n🛑 Press Ctrl+C to stop\n") try: app.run(host='0.0.0.0', port=3000, debug=False)Technical Analysis
The bundled test receiver accepts webhook requests without verifying an AgentMail signature, authenticating the sender, validating the request content type, or limiting the request size. Binding Flask to
0.0.0.0makes the endpoint reachable through every available network interface rather than only the local development host.The receiver also serializes the complete webhook payload to standard output. A legitimate
message.receivedpayload can contain sender and recipient addresses, subjects, email bodies, thread information, and attachment metadata. These values may consequently be disclosed to terminal history, container logs, service logs, or centralized logging systems.Although
references/WEBHOOKS.mddescribes signature v ...[truncated 1619 chars]- Remediation
View remediation
Remediation Suggestions
- Bind the development server to
127.0.0.1by default rather than0.0.0.0. - Require AgentMail webhook signature verification before parsing or processing a payload.
- Calculate the signature over the raw request body and compare it using a constant-time function such as
hmac.compare_digest. - Reject missing, malformed, expired, or invalid signatures with an appropriate error response.
- Validate that the request uses the expected content type and enforce a conservative maximum request-body size.
- Validate required fields and accepted event types before accessing nested data.
- Do not log complete webhook payloads. Log only redacted event identifiers and operational metadata.
- Redact email addresses, subjects, bodies, tokens, attachment data, and custom headers from logs.
- Clearly mark tunneling through ngrok as unsafe unless authentication and signature verification have already been enabled.
- Apply rate limiting and replay protection when the endpoint is exposed beyond localhost.
- Bind the development server to
