-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3394 from semgrep/merge-develop-to-release
Merge Develop into Release
- Loading branch information
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from twilio.rest import Client | ||
import html | ||
from xml.sax.saxutils import escape | ||
|
||
client = Client("accountSid", "authToken") | ||
XML = "<Response><Say>{}</Say><Hangup/></Response>" | ||
|
||
|
||
def fstring(to: str, msg: str) -> None: | ||
client.calls.create( | ||
# ruleid: twiml-injection | ||
twiml=f"<Response><Say>{msg}</Say><Hangup/></Response>", | ||
to=to, | ||
from_="555-555-5555", | ||
) | ||
|
||
|
||
def format_const(to: str, msg: str) -> None: | ||
twiml = XML.format(msg) | ||
client.calls.create( | ||
# ruleid: twiml-injection | ||
twiml=twiml, | ||
to=to, | ||
from_="555-555-5555", | ||
) | ||
|
||
|
||
def percent(to: str, msg: str) -> None: | ||
client.calls.create( | ||
# ruleid: twiml-injection | ||
twiml="<Response><Say>%s</Say><Hangup/></Response>" % msg, | ||
to=to, | ||
from_="555-555-5555", | ||
) | ||
|
||
|
||
def format(to: str, msg: str) -> None: | ||
client.calls.create( | ||
# ruleid: twiml-injection | ||
twiml="<Response><Say>{}</Say><Hangup/></Response>".format(msg), | ||
to=to, | ||
from_="555-555-5555", | ||
) | ||
|
||
|
||
def concat(to: str, msg: str) -> None: | ||
client.calls.create( | ||
# ruleid: twiml-injection | ||
twiml="<Response><Say>" + msg + "</Say><Hangup/></Response>", | ||
to=to, | ||
from_="555-555-5555", | ||
) | ||
|
||
|
||
def safe(to: str, msg: str) -> None: | ||
client.calls.create( | ||
# ok: twiml-injection | ||
twiml="<Response><Say>nsec</Say><Hangup/></Response>", | ||
to=to, | ||
from_="555-555-5555", | ||
) | ||
|
||
|
||
def also_safe(to: str, msg: str) -> None: | ||
client.calls.create( | ||
# ok: twiml-injection | ||
twiml="<Response><Say>nsec</Say><Hangup/></Response>", | ||
to=to, | ||
from_=f"{1+2}34-323-1234", | ||
) | ||
|
||
|
||
def html_escape(to: str, msg: str) -> None: | ||
client.calls.create( | ||
# ok: twiml-injection | ||
twiml="<Response><Say>" + html.escape(msg) + "</Say><Hangup/></Response>", | ||
to=to, | ||
from_="555-555-5555", | ||
) | ||
|
||
|
||
def xml_escape(to: str, msg: str) -> None: | ||
client.calls.create( | ||
# ok: twiml-injection | ||
twiml="<Response><Say>" + escape(msg) + "</Say><Hangup/></Response>", | ||
to=to, | ||
from_="555-555-5555", | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
rules: | ||
- id: twiml-injection | ||
languages: [python] | ||
severity: WARNING | ||
message: >- | ||
Using non-constant TwiML (Twilio Markup Language) argument when creating a | ||
Twilio conversation could allow the injection of additional TwiML commands | ||
metadata: | ||
cwe: | ||
- "CWE-91: XML Injection" | ||
owasp: | ||
- "A03:2021 - Injection" | ||
category: security | ||
technology: | ||
- python | ||
- twilio | ||
- twiml | ||
confidence: MEDIUM | ||
likelihood: HIGH | ||
impact: MEDIUM | ||
subcategory: vuln | ||
references: | ||
- https://codeberg.org/fennix/funjection | ||
mode: taint | ||
pattern-sources: | ||
- pattern: | | ||
f"..." | ||
- pattern: | | ||
"..." % ... | ||
- pattern: | | ||
"...".format(...) | ||
- patterns: | ||
- pattern: $ARG | ||
- pattern-inside: | | ||
def $F(..., $ARG, ...): | ||
... | ||
pattern-sanitizers: | ||
- pattern: xml.sax.saxutils.escape(...) | ||
- pattern: html.escape(...) | ||
|
||
pattern-sinks: | ||
- patterns: | ||
- pattern: | | ||
$CLIENT.calls.create(..., twiml=$SINK, ...) | ||
- focus-metavariable: $SINK |