SimpleSallap:SimpleMCP:InitalGoCleanup Limit read to ContentLength

Also enforce need for kind of a sane Content-Length header entry
in our case. NOTE: it does allow for 0 or other small content lengths,
which isnt necessarily valid.
This commit is contained in:
hanishkvc 2025-12-07 18:34:53 +05:30
parent e9dbe21c67
commit bc9dd580b9
1 changed files with 9 additions and 2 deletions

View File

@ -148,10 +148,17 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler):
if pr.path != '/mcp':
self.send_error(400, f"WARN:UnknownPath:{pr.path}")
return
body = self.rfile.read(gMe.nw.maxReadBytes)
if len(body) == gMe.nw.maxReadBytes:
bytesToRead = min(int(self.headers.get('Content-Length', -1)), gMe.nw.maxReadBytes)
if bytesToRead <= -1:
self.send_error(400, f"WARN:ContentLength missing:{pr.path}")
return
if bytesToRead == gMe.nw.maxReadBytes:
self.send_error(400, f"WARN:RequestOverflow:{pr.path}")
return
body = self.rfile.read(bytesToRead)
if len(body) != bytesToRead:
self.send_error(400, f"WARN:ContentLength mismatch:{pr.path}")
return
self.mcp_run(body)
def do_POST(self):