Skip to content

Commit fc43237

Browse files
authored
Merge branch 'master' into optional_tests
2 parents 48b13b8 + 591c291 commit fc43237

File tree

3 files changed

+90
-39
lines changed

3 files changed

+90
-39
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
5+
---
6+
7+
**Describe the bug**
8+
A clear and concise description of what the bug is.
9+
10+
**Expected behavior**
11+
A clear and concise description of what you expected to happen.
12+
13+
**Actual behavior**
14+
<!--- Paste verbatim command output between quotes -->
15+
```paste below
16+
17+
```
18+
19+
**Example code**
20+
<!--- Paste an example code that can be used to reproduce the problem between quotes -->
21+
```paste below
22+
23+
```
24+
25+
**OS / Environment**
26+
27+
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
28+
29+
**Inspec Version**
30+
<!--- Paste verbatim output from "inspec --version" between quotes -->
31+
```paste below
32+
33+
```
34+
35+
**Baseline Version**
36+
<!--- Paste version or git commit of the baseline between quotes -->
37+
```paste below
38+
39+
```
40+
41+
**Additional context**
42+
Add any other context about the problem here.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
**Is your feature request related to a problem? Please describe.**
8+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9+
10+
**Describe the solution you'd like**
11+
A clear and concise description of what you want to happen.
12+
13+
**Describe alternatives you've considered**
14+
A clear and concise description of any alternative solutions or features you've considered.
15+
16+
**Additional context**
17+
Add any other context or screenshots about the feature request here.

controls/nginx_spec.rb

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@
9292
end
9393

9494
# determine all required paths
95-
nginx_path = '/etc/nginx'
96-
nginx_conf = File.join(nginx_path, 'nginx.conf')
97-
nginx_confd = File.join(nginx_path, 'conf.d')
98-
nginx_enabled = File.join(nginx_path, 'sites-enabled')
99-
nginx_hardening = File.join(nginx_confd, '90.hardening.conf')
100-
conf_paths = [nginx_conf, nginx_hardening]
95+
nginx_path = '/etc/nginx'
96+
nginx_conf = File.join(nginx_path, 'nginx.conf')
97+
nginx_confd = File.join(nginx_path, 'conf.d')
98+
nginx_enabled = File.join(nginx_path, 'sites-enabled')
99+
nginx_parsed_config = command('nginx -T').stdout
101100

102101
options = {
103102
assignment_regex: /^\s*([^:]*?)\s*\ \s*(.*?)\s*;$/
@@ -148,12 +147,6 @@
148147
describe file(File.join(nginx_enabled, 'default')) do
149148
it { should_not be_file }
150149
end
151-
152-
conf_paths.each do |conf_path|
153-
describe file(conf_path) do
154-
it { should be_file }
155-
end
156-
end
157150
end
158151

159152
control 'nginx-04' do
@@ -169,7 +162,7 @@
169162
impact 1.0
170163
title 'Disable server_tokens directive'
171164
desc 'Disables emitting nginx version in error messages and in the “Server” response header field.'
172-
describe parse_config_file(nginx_conf, options) do
165+
describe parse_config(nginx_parsed_config, options) do
173166
its('server_tokens') { should eq 'off' }
174167
end
175168
end
@@ -178,16 +171,16 @@
178171
impact 1.0
179172
title 'Prevent buffer overflow attacks'
180173
desc 'Buffer overflow attacks are made possible by writing data to a buffer and exceeding that buffer boundary and overwriting memory fragments of a process. To prevent this in nginx we can set buffer size limitations for all clients.'
181-
describe parse_config_file(nginx_conf, options) do
174+
describe parse_config(nginx_parsed_config, options) do
182175
its('client_body_buffer_size') { should eq CLIENT_BODY_BUFFER_SIZE }
183176
end
184-
describe parse_config_file(nginx_conf, options) do
177+
describe parse_config(nginx_parsed_config, options) do
185178
its('client_max_body_size') { should eq CLIENT_MAX_BODY_SIZE }
186179
end
187-
describe parse_config_file(nginx_hardening, options) do
180+
describe parse_config(nginx_parsed_config, options) do
188181
its('client_header_buffer_size') { should eq CLIENT_HEADER_BUFFER_SIZE }
189182
end
190-
describe parse_config_file(nginx_hardening, options) do
183+
describe parse_config(nginx_parsed_config, options) do
191184
its('large_client_header_buffers') { should eq LARGE_CLIENT_HEADER_BUFFER }
192185
end
193186
end
@@ -196,10 +189,10 @@
196189
impact 1.0
197190
title 'Control simultaneous connections'
198191
desc 'NginxHttpLimitZone module to limit the number of simultaneous connections for the assigned session or as a special case, from one IP address.'
199-
describe parse_config_file(nginx_hardening, options) do
192+
describe parse_config(nginx_parsed_config, options) do
200193
its('limit_conn_zone') { should eq '$binary_remote_addr zone=default:10m' }
201194
end
202-
describe parse_config_file(nginx_hardening, options) do
195+
describe parse_config(nginx_parsed_config, options) do
203196
its('limit_conn') { should eq 'default 5' }
204197
end
205198
end
@@ -208,7 +201,7 @@
208201
impact 1.0
209202
title 'Prevent clickjacking'
210203
desc 'Do not allow the browser to render the page inside an frame or iframe.'
211-
describe parse_config_file(nginx_hardening, options_add_header) do
204+
describe parse_config(nginx_parsed_config, options_add_header) do
212205
its('add_header') { should include 'X-Frame-Options SAMEORIGIN' }
213206
end
214207
end
@@ -217,7 +210,7 @@
217210
impact 1.0
218211
title 'Enable Cross-site scripting filter'
219212
desc 'This header is used to configure the built in reflective XSS protection. This tells the browser to block the response if it detects an attack rather than sanitising the script.'
220-
describe parse_config_file(nginx_hardening, options_add_header) do
213+
describe parse_config(nginx_parsed_config, options_add_header) do
221214
its('add_header') { should include 'X-XSS-Protection "1; mode=block"' }
222215
end
223216
end
@@ -226,7 +219,7 @@
226219
impact 1.0
227220
title 'Disable content-type sniffing'
228221
desc 'It prevents browser from trying to mime-sniff the content-type of a response away from the one being declared by the server. It reduces exposure to drive-by downloads and the risks of user uploaded content that, with clever naming, could be treated as a different content-type, like an executable.'
229-
describe parse_config_file(nginx_hardening, options_add_header) do
222+
describe parse_config(nginx_parsed_config, options_add_header) do
230223
its('add_header') { should include 'X-Content-Type-Options nosniff' }
231224
end
232225
end
@@ -236,22 +229,21 @@
236229
title 'TLS Protocols'
237230
desc 'When choosing a cipher during an SSLv3 or TLSv1 handshake, normally the client\'s preference is used. If this directive is enabled, the server\'s preference will be used instead.'
238231
ref 'SSL Hardening config', url: 'https://mozilla.github.io/server-side-tls/ssl-config-generator/'
239-
describe file(nginx_hardening) do
240-
its('content') { should match(/^\s*ssl_protocols TLSv1.2;$/) }
241-
its('content') { should match(/^\s*ssl_session_tickets off;$/) }
242-
its('content') { should match(/^\s*ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';$/) }
243-
its('content') { should match(/^\s*ssl_prefer_server_ciphers on;$/) }
244-
its('content') { should match(%r{^\s*ssl_dhparam /etc/nginx/dh2048.pem;$}) }
245-
# its('content') { should match(/^\s*ssl on;$/) }
232+
describe parse_config(nginx_parsed_config, options) do
233+
its('ssl_protocols') { should eq 'TLSv1.2' }
234+
its('ssl_session_tickets') { should eq 'off' }
235+
its('ssl_ciphers') { should eq '\'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256\'' }
236+
its('ssl_prefer_server_ciphers') { should eq 'on' }
237+
its('ssl_dhparam') { should eq '/etc/nginx/dh2048.pem' }
246238
end
247239
end
248240

249241
control 'nginx-13' do
250242
impact 1.0
251243
title 'Add HSTS Header'
252244
desc 'HTTP Strict Transport Security (HSTS) is a web security policy mechanism which helps to protect websites against protocol downgrade attacks and cookie hijacking. It allows web servers to declare that web browsers (or other complying user agents) should only interact with it using secure HTTPS connections, and never via the insecure HTTP protocol. HSTS is an IETF standards track protocol and is specified in RFC 6797.'
253-
describe file(nginx_hardening) do
254-
its('content') { should match(/^\s*add_header Strict-Transport-Security max-age=15768000;$/) }
245+
describe parse_config(nginx_parsed_config, options_add_header) do
246+
its('add_header') { should include 'Strict-Transport-Security max-age=15768000' }
255247
end
256248
end
257249

@@ -271,8 +263,8 @@
271263
impact 1.0
272264
title 'Content-Security-Policy'
273265
desc 'The Content-Security-Policy HTTP response header helps you reduce XSS risks on modern browsers by declaring what dynamic resources are allowed to load via a HTTP Header'
274-
describe parse_config_file(nginx_hardening, options_add_header) do
275-
its('content') { should match(/^\s*add_header Content-Security-Policy "script-src 'self'; object-src 'self'";$/) }
266+
describe parse_config(nginx_parsed_config, options_add_header) do
267+
its('add_header') { should include 'Content-Security-Policy "script-src \'self\'; object-src \'self\'"' }
276268
end
277269
end
278270

@@ -281,25 +273,25 @@
281273
title 'Set cookie with HttpOnly and Secure flag'
282274
desc 'You can mitigate most of the common Cross Site Scripting attack using HttpOnly and Secure flag in a cookie. Without having HttpOnly and Secure, it is possible to steal or manipulate web application session and cookies and it’s dangerous.'
283275
only_if { NGINX_COOKIE_FLAG_MODULE != false }
284-
describe parse_config_file(nginx_hardening, options_add_header) do
285-
its('content') { should match(/^\s*set_cookie_flag * HttpOnly secure;$/) }
276+
describe parse_config(nginx_parsed_config, options_add_header) do
277+
its('set_cookie_flag') { should include '* HttpOnly secure' }
286278
end
287279
end
288280

289281
control 'nginx-17' do
290282
impact 1.0
291283
title 'Control timeouts to improve performance'
292284
desc 'Control timeouts to improve server performance and cut clients.'
293-
describe parse_config_file(nginx_conf, options) do
285+
describe parse_config(nginx_parsed_config, options) do
294286
its('keepalive_timeout') { should eq KEEPALIVE_TIMEOUT }
295287
end
296-
describe parse_config_file(nginx_hardening, options) do
288+
describe parse_config(nginx_parsed_config, options) do
297289
its('client_body_timeout') { should eq CLIENT_BODY_TIMEOUT }
298290
end
299-
describe parse_config_file(nginx_hardening, options) do
291+
describe parse_config(nginx_parsed_config, options) do
300292
its('client_header_timeout') { should eq CLIENT_HEADER_TIMEOUT }
301293
end
302-
describe parse_config_file(nginx_hardening, options) do
294+
describe parse_config(nginx_parsed_config, options) do
303295
its('send_timeout') { should eq SEND_TIMEOUT }
304296
end
305297
end

0 commit comments

Comments
 (0)