Skip to content

Commit 0baa8a7

Browse files
committed
Merge remote-tracking branch 'origin/eric.navarro/update-contributing-docs' into eric.navarro/update-contributing-docs
2 parents 612a44e + 3dab523 commit 0baa8a7

File tree

18 files changed

+199
-186
lines changed

18 files changed

+199
-186
lines changed

.riot/requirements/1854ba5.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
# This file is autogenerated by pip-compile with Python 3.11
33
# by the following command:
44
#
5-
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/1854ba5.in
5+
# pip-compile --no-annotate .riot/requirements/1854ba5.in
66
#
7-
attrs==22.2.0
8-
coverage[toml]==7.2.2
9-
dnspython==2.3.0
7+
attrs==23.1.0
8+
coverage[toml]==7.3.0
9+
dnspython==2.4.2
1010
hypothesis==6.45.0
1111
iniconfig==2.0.0
12-
mock==5.0.1
12+
mock==5.1.0
1313
mongoengine==0.27.0
1414
opentracing==2.4.0
15-
packaging==23.0
16-
pluggy==1.0.0
17-
pymongo==4.3.3
18-
pytest==7.2.2
19-
pytest-cov==4.0.0
20-
pytest-mock==3.10.0
15+
packaging==23.1
16+
pluggy==1.2.0
17+
pymongo==4.5.0
18+
pytest==7.4.0
19+
pytest-cov==4.1.0
20+
pytest-mock==3.11.1
2121
sortedcontainers==2.4.0

.riot/requirements/1922cee.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

.riot/requirements/1b81325.txt

Lines changed: 0 additions & 26 deletions
This file was deleted.

.riot/requirements/1fd1158.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
5-
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/1fd1158.in
5+
# pip-compile --no-annotate .riot/requirements/1fd1158.in
66
#
7-
attrs==22.2.0
8-
coverage[toml]==7.2.2
9-
dnspython==2.3.0
10-
exceptiongroup==1.1.1
7+
attrs==23.1.0
8+
coverage[toml]==7.3.0
9+
dnspython==2.4.2
10+
exceptiongroup==1.1.3
1111
hypothesis==6.45.0
1212
iniconfig==2.0.0
13-
mock==5.0.1
13+
mock==5.1.0
1414
mongoengine==0.27.0
1515
opentracing==2.4.0
16-
packaging==23.0
17-
pluggy==1.0.0
18-
pymongo==4.3.3
19-
pytest==7.2.2
20-
pytest-cov==4.0.0
21-
pytest-mock==3.10.0
16+
packaging==23.1
17+
pluggy==1.2.0
18+
pymongo==4.5.0
19+
pytest==7.4.0
20+
pytest-cov==4.1.0
21+
pytest-mock==3.11.1
2222
sortedcontainers==2.4.0
2323
tomli==2.0.1

.riot/requirements/41bf6ef.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.9
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/41bf6ef.in
6+
#
7+
attrs==23.1.0
8+
coverage[toml]==7.3.0
9+
dnspython==2.4.2
10+
exceptiongroup==1.1.3
11+
hypothesis==6.45.0
12+
iniconfig==2.0.0
13+
mock==5.1.0
14+
mongoengine==0.27.0
15+
opentracing==2.4.0
16+
packaging==23.1
17+
pluggy==1.2.0
18+
pymongo==4.5.0
19+
pytest==7.4.0
20+
pytest-cov==4.1.0
21+
pytest-mock==3.11.1
22+
sortedcontainers==2.4.0
23+
tomli==2.0.1

.riot/requirements/4bf8418.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.7
3+
# by the following command:
4+
#
5+
# pip-compile --config=pyproject.toml --no-annotate --resolver=backtracking .riot/requirements/4bf8418.in
6+
#
7+
attrs==23.1.0
8+
coverage[toml]==7.2.7
9+
dnspython==2.3.0
10+
exceptiongroup==1.1.3
11+
hypothesis==6.45.0
12+
importlib-metadata==6.7.0
13+
iniconfig==2.0.0
14+
mock==5.1.0
15+
mongoengine==0.27.0
16+
opentracing==2.4.0
17+
packaging==23.1
18+
pluggy==1.2.0
19+
pymongo==4.5.0
20+
pytest==7.4.0
21+
pytest-cov==4.1.0
22+
pytest-mock==3.11.1
23+
sortedcontainers==2.4.0
24+
tomli==2.0.1
25+
typing-extensions==4.7.1
26+
zipp==3.15.0

.riot/requirements/a1e6119.txt

Lines changed: 0 additions & 23 deletions
This file was deleted.

.riot/requirements/bddee76.txt

Lines changed: 0 additions & 23 deletions
This file was deleted.

.riot/requirements/c01e3b4.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
5-
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/c01e3b4.in
5+
# pip-compile --no-annotate .riot/requirements/c01e3b4.in
66
#
77
attrs==22.2.0
88
coverage[toml]==7.2.2

.riot/requirements/f92d9dc.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# pip-compile --no-annotate .riot/requirements/f92d9dc.in
6+
#
7+
attrs==23.1.0
8+
coverage[toml]==7.3.0
9+
dnspython==2.4.2
10+
exceptiongroup==1.1.3
11+
hypothesis==6.45.0
12+
iniconfig==2.0.0
13+
mock==5.1.0
14+
mongoengine==0.27.0
15+
opentracing==2.4.0
16+
packaging==23.1
17+
pluggy==1.2.0
18+
pymongo==4.5.0
19+
pytest==7.4.0
20+
pytest-cov==4.1.0
21+
pytest-mock==3.11.1
22+
sortedcontainers==2.4.0
23+
tomli==2.0.1

ddtrace/appsec/iast/taint_sinks/command_injection.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import List
2+
from typing import Union
3+
14
from ddtrace.appsec.iast import oce
25
from ddtrace.appsec.iast.constants import EVIDENCE_CMDI
36
from ddtrace.appsec.iast.constants import VULN_CMDI
@@ -16,3 +19,21 @@ def report(cls, evidence_value=None, sources=None):
1619

1720
evidence_value, sources = taint_ranges_as_evidence_info(evidence_value)
1821
super(CommandInjection, cls).report(evidence_value=evidence_value, sources=sources)
22+
23+
24+
def _iast_report_cmdi(shell_args):
25+
# type: (Union[str, List[str]]) -> None
26+
report_cmdi = ""
27+
from ddtrace.appsec.iast._taint_tracking import get_tainted_ranges
28+
from ddtrace.appsec.iast._taint_tracking.aspects import join_aspect
29+
30+
if isinstance(shell_args, (list, tuple)):
31+
for arg in shell_args:
32+
if get_tainted_ranges(arg):
33+
report_cmdi = join_aspect(" ", shell_args)
34+
break
35+
elif get_tainted_ranges(shell_args):
36+
report_cmdi = shell_args
37+
38+
if report_cmdi:
39+
CommandInjection.report(evidence_value=report_cmdi)

ddtrace/contrib/pymongo/client.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,26 @@ def _datadog_trace_operation(self, operation):
143143
span.set_tag(ANALYTICS_SAMPLE_RATE_KEY, sample_rate)
144144
return span
145145

146-
# Pymongo >= 3.12
146+
if VERSION >= (4, 5, 0):
147+
148+
@contextlib.contextmanager
149+
def checkout(self, *args, **kwargs):
150+
with self.__wrapped__.checkout(*args, **kwargs) as s:
151+
if not isinstance(s, TracedSocket):
152+
s = TracedSocket(s)
153+
ddtrace.Pin.get_from(self).onto(s)
154+
yield s
155+
156+
else:
157+
158+
@contextlib.contextmanager
159+
def get_socket(self, *args, **kwargs):
160+
with self.__wrapped__.get_socket(*args, **kwargs) as s:
161+
if not isinstance(s, TracedSocket):
162+
s = TracedSocket(s)
163+
ddtrace.Pin.get_from(self).onto(s)
164+
yield s
165+
147166
if VERSION >= (3, 12, 0):
148167

149168
def run_operation(self, sock_info, operation, *args, **kwargs):
@@ -159,7 +178,6 @@ def run_operation(self, sock_info, operation, *args, **kwargs):
159178
set_query_rowcount(docs=result.docs, span=span)
160179
return result
161180

162-
# Pymongo >= 3.9, <3.12
163181
elif (3, 9, 0) <= VERSION < (3, 12, 0):
164182

165183
def run_operation_with_response(self, sock_info, operation, *args, **kwargs):
@@ -175,7 +193,6 @@ def run_operation_with_response(self, sock_info, operation, *args, **kwargs):
175193
set_query_rowcount(docs=result.docs, span=span)
176194
return result
177195

178-
# Pymongo < 3.9
179196
else:
180197

181198
def send_message_with_response(self, operation, *args, **kwargs):
@@ -200,14 +217,6 @@ def send_message_with_response(self, operation, *args, **kwargs):
200217
set_query_rowcount(docs=docs, span=span)
201218
return result
202219

203-
@contextlib.contextmanager
204-
def get_socket(self, *args, **kwargs):
205-
with self.__wrapped__.get_socket(*args, **kwargs) as s:
206-
if not isinstance(s, TracedSocket):
207-
s = TracedSocket(s)
208-
ddtrace.Pin.get_from(self).onto(s)
209-
yield s
210-
211220
@staticmethod
212221
def _is_query(op):
213222
# NOTE: _Query should always have a spec field

ddtrace/contrib/pymongo/patch.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
# Original Client class
2929
_MongoClient = pymongo.MongoClient
3030

31+
_VERSION = pymongo.version_tuple
32+
_CHECKOUT_FN_NAME = "get_socket" if _VERSION < (4, 5) else "checkout"
33+
3134

3235
def patch():
3336
patch_pymongo_module()
@@ -50,15 +53,15 @@ def patch_pymongo_module():
5053
# Whenever a pymongo command is invoked, the lib either:
5154
# - Creates a new socket & performs a TCP handshake
5255
# - Grabs a socket already initialized before
53-
_w("pymongo.server", "Server.get_socket", traced_get_socket)
56+
_w("pymongo.server", "Server.%s" % _CHECKOUT_FN_NAME, traced_get_socket)
5457

5558

5659
def unpatch_pymongo_module():
5760
if not getattr(pymongo, "_datadog_patch", False):
5861
return
5962
pymongo._datadog_patch = False
6063

61-
_u(pymongo.server.Server, "get_socket")
64+
_u(pymongo.server.Server, _CHECKOUT_FN_NAME)
6265

6366

6467
@contextlib.contextmanager
@@ -70,7 +73,9 @@ def traced_get_socket(wrapped, instance, args, kwargs):
7073
return
7174

7275
with pin.tracer.trace(
73-
"pymongo.get_socket", service=trace_utils.int_service(pin, config.pymongo), span_type=SpanTypes.MONGODB
76+
"pymongo.%s" % _CHECKOUT_FN_NAME,
77+
service=trace_utils.int_service(pin, config.pymongo),
78+
span_type=SpanTypes.MONGODB,
7479
) as span:
7580
span.set_tag_str(COMPONENT, config.pymongo.integration_name)
7681
span.set_tag_str(db.SYSTEM, mongo.SERVICE)

0 commit comments

Comments
 (0)