Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MODULES-10530] Add request limiting directives on virtual host level #1996

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,36 @@
# @param oidc_settings
# An Apache::OIDCSettings Struct containing (mod_auth_openidc settings)[https://github.com/zmartzone/mod_auth_openidc/blob/master/auth_openidc.conf].
#
# @param limitreqfields
# The `limitreqfields` parameter sets the maximum number of request header fields in
# an HTTP request. This directive gives the server administrator greater control over
# abnormal client request behavior, which may be useful for avoiding some forms of
# denial-of-service attacks. The value should be increased if normal clients see an error
# response from the server that indicates too many fields were sent in the request.
#
# @param limitreqfieldsize
# The `limitreqfieldsize` parameter sets the maximum ammount of _bytes_ that will
# be allowed within a request header.
#
# @param limitreqline
# Limit the size of the HTTP request line that will be accepted from the client
# This directive sets the number of bytes that will be allowed on the HTTP
# request-line. The LimitRequestLine directive allows the server administrator
# to set the limit on the allowed size of a client's HTTP request-line. Since
# the request-line consists of the HTTP method, URI, and protocol version, the
# LimitRequestLine directive places a restriction on the length of a request-URI
# allowed for a request on the server. A server needs this value to be large
# enough to hold any of its resource names, including any information that might
# be passed in the query part of a GET request.
#
# @param limitreqbody
# Restricts the total size of the HTTP request body sent from the client
# The LimitRequestBody directive allows the user to set a limit on the allowed
# size of an HTTP request message body within the context in which the
# directive is given (server, per-directory, per-file or per-location). If the
# client request exceeds that limit, the server will return an error response
# instead of servicing the request.
#
define apache::vhost(
Variant[Boolean,String] $docroot,
$manage_docroot = true,
Expand Down Expand Up @@ -1710,6 +1740,10 @@
Optional[Variant[Stdlib::Absolutepath, Enum['disabled']]] $fallbackresource = undef,
$scriptalias = undef,
$scriptaliases = [],
Optional[Integer] $limitreqfieldsize = undef,
Optional[Integer] $limitreqfields = undef,
Optional[Integer] $limitreqline = undef,
Optional[Integer] $limitreqbody = undef,
$proxy_dest = undef,
$proxy_dest_match = undef,
$proxy_dest_reverse_match = undef,
Expand Down
24 changes: 24 additions & 0 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@
'path' => '/usr/share/fooscripts$1',
},
],
'limitreqfieldsize' => 8190,
'limitreqfields' => 100,
'limitreqline' => 8190,
'limitreqbody' => 0,
'proxy_dest' => '/',
'proxy_pass' => [
{
Expand Down Expand Up @@ -518,6 +522,26 @@
}
end
it { is_expected.to contain_concat__fragment('rspec.example.com-apache-header') }
it {
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
content: %r{^\s+LimitRequestFieldSize 8190$},
)
}
it {
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
content: %r{^\s+LimitRequestFields 100$},
)
}
it {
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
content: %r{^\s+LimitRequestLine 8190$},
)
}
it {
is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with(
content: %r{^\s+LimitRequestBody 0$},
)
}
it { is_expected.to contain_concat__fragment('rspec.example.com-docroot') }
it { is_expected.to contain_concat__fragment('rspec.example.com-aliases') }
it { is_expected.to contain_concat__fragment('rspec.example.com-itk') }
Expand Down
12 changes: 12 additions & 0 deletions templates/vhost/_file_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@
ProtocolsHonorOrder <%= scope.call_function('apache::bool2httpd', [@protocols_honor_order]) %>
<%- end -%>
<% end -%>
<% if @limitreqfieldsize -%>
LimitRequestFieldSize <%= @limitreqfieldsize %>
<% end -%>
<% if @limitreqfields -%>
LimitRequestFields <%= @limitreqfields %>
<% end -%>
<% if @limitreqline -%>
LimitRequestLine <%= @limitreqline %>
<% end -%>
<% if @limitreqbody -%>
LimitRequestBody <%= @limitreqbody %>
<% end -%>