Skip to content

Commit 36e3aaf

Browse files
committed
Limit number of multicalls to 20
1 parent 3bcd97b commit 36e3aaf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tests/unit/legacy/api/xmlrpc/test_xmlrpc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,3 +858,14 @@ def test_missing_multicall_method(self):
858858
assert exc.value.faultString == (
859859
'ValueError: Method name not provided'
860860
)
861+
862+
def test_too_many_multicalls_method(self):
863+
request = pretend.stub()
864+
args = [{'methodName': 'nah'}] * 21
865+
866+
with pytest.raises(xmlrpc.XMLRPCWrappedError) as exc:
867+
xmlrpc.multicall(request, args)
868+
869+
assert exc.value.faultString == (
870+
'ValueError: Multicall limit is 20 calls'
871+
)

warehouse/legacy/api/xmlrpc/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
)
3434

3535

36+
_MAX_MULTICALLS = 20
37+
38+
3639
def xmlrpc_method(**kwargs):
3740
"""
3841
Support multiple endpoints serving the same views by chaining calls to
@@ -453,8 +456,11 @@ def multicall(request, args):
453456
)
454457

455458
if not all(arg.get('methodName') for arg in args):
459+
raise XMLRPCWrappedError(ValueError('Method name not provided'))
460+
461+
if len(args) > _MAX_MULTICALLS:
456462
raise XMLRPCWrappedError(
457-
ValueError('Method name not provided')
463+
ValueError(f'Multicall limit is {_MAX_MULTICALLS} calls')
458464
)
459465

460466
responses = []

0 commit comments

Comments
 (0)