mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
Restrict POST query size (#519)
* indexing: restrict POST body appended to query to 16384, avoid reading very large POST requests on indexing
This commit is contained in:
parent
0d819aadeb
commit
c7fdfe72a7
@ -181,6 +181,8 @@ class POSTInputRequest(DirectWSGIInputRequest):
|
|||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
class MethodQueryCanonicalizer(object):
|
class MethodQueryCanonicalizer(object):
|
||||||
|
MAX_POST_SIZE = 16384
|
||||||
|
|
||||||
def __init__(self, method, mime, length, stream,
|
def __init__(self, method, mime, length, stream,
|
||||||
buffered_stream=None,
|
buffered_stream=None,
|
||||||
environ=None):
|
environ=None):
|
||||||
@ -210,7 +212,9 @@ class MethodQueryCanonicalizer(object):
|
|||||||
if length <= 0:
|
if length <= 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
query = b''
|
# max POST query allowed, for size considerations, only read upto this size
|
||||||
|
length = min(length, self.MAX_POST_SIZE)
|
||||||
|
query = []
|
||||||
|
|
||||||
while length > 0:
|
while length > 0:
|
||||||
buff = stream.read(length)
|
buff = stream.read(length)
|
||||||
@ -219,7 +223,9 @@ class MethodQueryCanonicalizer(object):
|
|||||||
if not buff:
|
if not buff:
|
||||||
break
|
break
|
||||||
|
|
||||||
query += buff
|
query.append(buff)
|
||||||
|
|
||||||
|
query = b''.join(query)
|
||||||
|
|
||||||
if buffered_stream:
|
if buffered_stream:
|
||||||
buffered_stream.write(query)
|
buffered_stream.write(query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user