Commit f34ef945 authored by Andreas Jung's avatar Andreas Jung

- Collector #1003: added new 'http-header-max-length' directive

        to zope.conf to specific the maximum length of a HTTP request
        header before it is considered as a possible DoS attack and
        discarded.
parent 9e9b156a
...@@ -46,6 +46,11 @@ Zope Changes ...@@ -46,6 +46,11 @@ Zope Changes
Bugs fixed Bugs fixed
- Collector #1003: added new 'http-header-max-length' directive
to zope.conf to specific the maximum length of a HTTP request
header before it is considered as a possible DoS attack and
discarded.
- Collector #1371: added new 'cgi-maxlen' directive to zope.conf - Collector #1371: added new 'cgi-maxlen' directive to zope.conf
to limit the amount of form data being processed by Zope to limit the amount of form data being processed by Zope
to prevent DoS attacks to prevent DoS attacks
......
...@@ -44,6 +44,7 @@ from cStringIO import StringIO ...@@ -44,6 +44,7 @@ from cStringIO import StringIO
from PubCore import handle from PubCore import handle
from HTTPResponse import make_response from HTTPResponse import make_response
from ZPublisher.HTTPRequest import HTTPRequest from ZPublisher.HTTPRequest import HTTPRequest
from App.config import getConfiguration
from medusa.http_server import http_server,get_header, http_channel, VERSION_STRING from medusa.http_server import http_server,get_header, http_channel, VERSION_STRING
import asyncore import asyncore
...@@ -288,13 +289,13 @@ class zhttp_channel(http_channel): ...@@ -288,13 +289,13 @@ class zhttp_channel(http_channel):
closed = 0 closed = 0
no_more_requests = 0 no_more_requests = 0
zombie_timeout=100*60 # 100 minutes zombie_timeout=100*60 # 100 minutes
max_header_len = 8196
def __init__(self, server, conn, addr): def __init__(self, server, conn, addr):
http_channel.__init__(self, server, conn, addr) http_channel.__init__(self, server, conn, addr)
requestCloseOnExec(conn) requestCloseOnExec(conn)
self.queue=[] self.queue=[]
self.working=0 self.working=0
self.max_header_len = getConfiguration().http_header_max_length
def push(self, producer, send=1): def push(self, producer, send=1):
# this is thread-safe when send is false # this is thread-safe when send is false
...@@ -365,7 +366,8 @@ class zhttp_channel(http_channel): ...@@ -365,7 +366,8 @@ class zhttp_channel(http_channel):
else: else:
# we are receiving header (request) data # we are receiving header (request) data
self.in_buffer = self.in_buffer + data self.in_buffer = self.in_buffer + data
if len(self.in_buffer) > self.max_header_len: inbuf_len = len(self.in_buffer)
if inbuf_len > self.max_header_len:
# Don't bother with a proper response header, # Don't bother with a proper response header,
# we are probably under attack and that would just consume # we are probably under attack and that would just consume
# precious resources. # precious resources.
...@@ -373,7 +375,7 @@ class zhttp_channel(http_channel): ...@@ -373,7 +375,7 @@ class zhttp_channel(http_channel):
# Hanging's too good for them! # Hanging's too good for them!
# Unfortunate side effect: the attack gets logged to the # Unfortunate side effect: the attack gets logged to the
# event log, but not the access log. # event log, but not the access log.
raise ValueError('HTTP headers invalid (too long)') raise ValueError('HTTP headers invalid (too long) (got: %d bytes, allowed %d bytes' % (inbuf_len, self.max_header_len))
class zhttp_server(http_server): class zhttp_server(http_server):
"http server" "http server"
......
...@@ -99,6 +99,9 @@ def cgi_maxlen(value): ...@@ -99,6 +99,9 @@ def cgi_maxlen(value):
import cgi import cgi
cgi.maxlen = value cgi.maxlen = value
def http_header_max_length(value):
return value
# server handlers # server handlers
def root_handler(config): def root_handler(config):
......
...@@ -530,6 +530,12 @@ ...@@ -530,6 +530,12 @@
</description> </description>
</key> </key>
<key name="http-header-max-length" default="8192" handler="http_header_max_length" datatype="integer">
<description>
Maximum size of received HTTP header being processed by Zope
</description>
</key>
<key name="dns-server" datatype=".dns_resolver" attribute="dns_resolver"> <key name="dns-server" datatype=".dns_resolver" attribute="dns_resolver">
<description> <description>
Specify the ip address of your DNS server in order to cause resolved Specify the ip address of your DNS server in order to cause resolved
......
...@@ -431,6 +431,20 @@ instancehome $INSTANCE ...@@ -431,6 +431,20 @@ instancehome $INSTANCE
# cgi-maxlen 10000 # cgi-maxlen 10000
# Directive: http-header-max-length
#
# Description:
# Maximum number of bytes allowed within a HTTP request header. The request
# is discarded and considered as a DoS attack if the header size exceeds
# this limit.
#
# Default: 8192
#
# Example:
#
# http-header-max-length 16384
# Directive: automatically-quote-dtml-request-data # Directive: automatically-quote-dtml-request-data
# #
# Description: # Description:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment