Commit b47ad2f 1 parent 1c8388f commit b47ad2f Copy full SHA for b47ad2f
File tree 5 files changed +47
-4
lines changed
5 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -14,20 +14,23 @@ defmodule Sobelow.Config.HSTS do
14
14
15
15
@ uid 8
16
16
@ finding_type "Config.HSTS: HSTS Not Enabled"
17
+ @ ignored_files [ "runtime.exs" ]
17
18
18
19
use Sobelow.Finding
19
20
20
21
def run ( dir_path , configs ) do
21
22
Enum . each ( configs , fn conf ->
22
- path = dir_path <> conf
23
+ unless Enum . member? ( @ ignored_files , conf ) do
24
+ path = dir_path <> conf
23
25
24
- Config . get_configs_by_file ( :https , path )
25
- |> handle_https ( path )
26
+ Config . get_configs_by_file ( :https , path )
27
+ |> handle_https ( path )
28
+ end
26
29
end )
27
30
end
28
31
29
32
defp handle_https ( opts , file ) do
30
- # If HTTPS configs were found in any config file and there
33
+ # If HTTPS configs were found in any compile-time config file and there
31
34
# are no accompanying HSTS configs, add an HSTS finding.
32
35
if length ( opts ) > 0 && Enum . empty? ( Config . get_configs ( :force_ssl , file ) ) do
33
36
add_finding ( file )
Original file line number Diff line number Diff line change
1
+ defmodule SobelowTest.Config.HstsTest do
2
+ use ExUnit.Case
3
+ alias Sobelow.Config.HSTS
4
+
5
+ setup do
6
+ Application . put_env ( :sobelow , :format , "json" )
7
+ Sobelow.Fingerprint . start_link ( )
8
+ Sobelow.FindingLog . start_link ( )
9
+
10
+ :ok
11
+ end
12
+
13
+ test "complains when force_ssl is missing in prod.exs" do
14
+ HSTS . run ( "./test/fixtures/hsts/" , [ "missing_prod.exs" ] )
15
+ assert Sobelow.FindingLog . json ( "1" ) =~ "Config.HSTS: HSTS Not Enabled"
16
+ end
17
+
18
+ test "does not complain when force_ssl is present in prod.exs" do
19
+ HSTS . run ( "./test/fixtures/hsts/" , [ "present_prod.exs" ] )
20
+ refute Sobelow.FindingLog . json ( "1" ) =~ "Config.HSTS: HSTS Not Enabled"
21
+ end
22
+
23
+ test "does not complain when force_ssl is missing in runtime.exs" do
24
+ HSTS . run ( "./test/fixtures/hsts/" , [ "runtime.exs" ] )
25
+ refute Sobelow.FindingLog . json ( "1" ) =~ "Config.HSTS: HSTS Not Enabled"
26
+ end
27
+ end
Original file line number Diff line number Diff line change
1
+ use Config
2
+
3
+ config :phoenix_app ,
4
+ https: [ ]
Original file line number Diff line number Diff line change
1
+ use Config
2
+
3
+ config :phoenix_app ,
4
+ https: [ ] ,
5
+ force_ssl: [ hsts: true ]
Original file line number Diff line number Diff line change
1
+ use Config
2
+
3
+ config :phoenix_app ,
4
+ https: [ ]
You can’t perform that action at this time.
0 commit comments