fix(dingtalk,api): validate webhook URL origin, cap cache, reject header injection - #6928
Closed
aaronlab wants to merge 1 commit into
Closed
Conversation
…ache, reject header injection dingtalk.py: The session_webhook URL from incoming DingTalk messages is POSTed to without any origin validation (line 290), enabling SSRF attacks via crafted webhook URLs (e.g. http://169.254.169.254/ to reach cloud metadata). Add a regex check that only accepts the official DingTalk API origin (https://api.dingtalk.com/). Also cap _session_webhooks dict at 500 entries with FIFO eviction to prevent unbounded memory growth from long-running gateway instances. api_server.py: The X-Hermes-Session-Id request header is accepted and echoed back into response headers (lines 675, 697) without sanitization. A session ID containing \r\n enables HTTP response splitting / header injection. Add a check that rejects session IDs containing control characters (\r, \n, \x00). Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dingtalk.py — SSRF via session_webhook: The
session_webhookURL from incoming DingTalk messages is stored and later POSTed to (line 290) without any origin validation. An attacker controlling the DingTalk message can setsession_webhooktohttp://169.254.169.254/latest/meta-data/(cloud metadata),http://127.0.0.1:6379(Redis), or any internal service. Fix: add a regex check that only accepts the officialhttps://api.dingtalk.com/origin.dingtalk.py — unbounded memory growth:
_session_webhooksdict grows without limit — every uniquechat_idcreates a permanent entry, cleared only ondisconnect(). A long-running gateway instance (months) accumulates millions of entries → OOM. Fix: cap at 500 entries with FIFO eviction (consistent with the dedup pattern at lines 55-56).api_server.py — HTTP header injection:
X-Hermes-Session-Idis accepted from request headers (line 534) and echoed directly into response headers (lines 675, 697) without sanitization. A session ID containing\r\nenables HTTP response splitting. Fix: reject session IDs containing control characters (\r,\n,\x00) with a 400 response.Test plan
https://api.dingtalk.com/...webhook URLs are acceptedhttp://169.254.169.254/) are silently rejected\r\nare rejected with 400🤖 Generated with Claude Code