Skip to content

Commit 6c63d3c

Browse files
authored
Update GitHub Action & Credo vsn / associated checks (#156)
* Update the Github workflow to target Elixir 1.16.x * update credo to 1.7.4 * update several is_x? functions to be x? * update the is_vuln? fuction to be vuln? * update the is_plug? fuction to be plug? * rest of credo complaints
1 parent c755ba7 commit 6c63d3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+181
-179
lines changed

.github/workflows/elixir.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
otp: 25.1
3636
- elixir: '1.15.x'
3737
otp: 26.0
38+
- elixir: '1.16.x'
39+
otp: 26.2
3840

3941
steps:
4042
- name: Setup Elixir
@@ -56,11 +58,11 @@ jobs:
5658
run: mix hex.audit
5759

5860
- name: Check Formatting
59-
if: ${{ matrix.elixir == '1.15.x' }} # we only care about formatting for latest version of Elixir
61+
if: ${{ matrix.elixir == '1.16.x' }} # we only care about formatting for latest version of Elixir
6062
run: mix format --check-formatted
6163

6264
- name: Compiles w/o Warnings
63-
if: ${{ matrix.elixir == '1.15.x' }} # we only care about warnings for latest version of Elixir
65+
if: ${{ matrix.elixir == '1.16.x' }} # we only care about warnings for latest version of Elixir
6466
run: mix compile --warnings-as-errors
6567

6668
- name: Credo

lib/sobelow.ex

+10-10
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ defmodule Sobelow do
324324
phoenix_files =
325325
Enum.reduce(meta_files, %{routers: [], endpoints: []}, fn meta_file, acc ->
326326
cond do
327-
meta_file.is_router? ->
327+
meta_file.router? ->
328328
Map.update!(acc, :routers, &[meta_file.file_path | &1])
329329

330-
meta_file.is_endpoint? ->
330+
meta_file.endpoint? ->
331331
Map.update!(acc, :endpoints, &[meta_file.file_path | &1])
332332

333333
true ->
@@ -351,7 +351,7 @@ defmodule Sobelow do
351351
ignored_files = get_env(:ignored_files)
352352

353353
Utils.template_files(root)
354-
|> Enum.reject(&is_ignored_file(&1, ignored_files))
354+
|> Enum.reject(&ignored_file?(&1, ignored_files))
355355
|> Enum.map(&get_template_meta/1)
356356
|> Map.new()
357357
end
@@ -368,7 +368,7 @@ defmodule Sobelow do
368368
filename: filename,
369369
raw: raw,
370370
ast: [ast],
371-
is_controller?: false
371+
controller?: false
372372
}
373373
}
374374
end
@@ -377,7 +377,7 @@ defmodule Sobelow do
377377
ignored_files = get_env(:ignored_files)
378378

379379
Utils.all_files(root)
380-
|> Enum.reject(&is_ignored_file(&1, ignored_files))
380+
|> Enum.reject(&ignored_file?(&1, ignored_files))
381381
|> Enum.map(&get_file_meta/1)
382382
end
383383

@@ -391,9 +391,9 @@ defmodule Sobelow do
391391
filename: Utils.normalize_path(filename),
392392
file_path: Path.expand(filename),
393393
def_funs: def_funs,
394-
is_controller?: Utils.is_controller?(use_funs),
395-
is_router?: Utils.is_router?(use_funs),
396-
is_endpoint?: Utils.is_endpoint?(use_funs)
394+
controller?: Utils.controller?(use_funs),
395+
router?: Utils.router?(use_funs),
396+
is_endpoint?: Utils.endpoint?(use_funs)
397397
}
398398
end
399399

@@ -656,15 +656,15 @@ defmodule Sobelow do
656656
|> Enum.map(&get_mod/1)
657657
end
658658

659-
def is_vuln?({vars, _, _}) do
659+
def vuln?({vars, _, _}) do
660660
if Enum.empty?(vars) do
661661
false
662662
else
663663
true
664664
end
665665
end
666666

667-
defp is_ignored_file(filename, ignored_files) do
667+
defp ignored_file?(filename, ignored_files) do
668668
Enum.any?(ignored_files, fn ignored_file ->
669669
String.ends_with?(ignored_file, filename)
670670
end)

lib/sobelow/ci/os.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.CI.OS do
1717
use Sobelow.Finding
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Finding.init(@finding_type, meta_file.filename, confidence)
2323
|> Finding.multi_from_def(fun, parse_def(fun))

lib/sobelow/ci/system.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.CI.System do
1717
use Sobelow.Finding
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Finding.init(@finding_type, meta_file.filename, confidence)
2323
|> Finding.multi_from_def(fun, parse_def(fun))

lib/sobelow/config.ex

+8-8
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ defmodule Sobelow.Config do
120120
|> Enum.reject(fn {type, _, _} -> type !== :plug end)
121121
end
122122

123-
def is_vuln_pipeline?({:pipeline, _, [_name, [do: block]]}, :csrf) do
123+
def vuln_pipeline?({:pipeline, _, [_name, [do: block]]}, :csrf) do
124124
plugs = get_plug_list(block)
125-
has_csrf? = Enum.any?(plugs, &is_plug?(&1, :protect_from_forgery))
126-
has_session? = Enum.any?(plugs, &is_plug?(&1, :fetch_session))
125+
has_csrf? = Enum.any?(plugs, &plug?(&1, :protect_from_forgery))
126+
has_session? = Enum.any?(plugs, &plug?(&1, :fetch_session))
127127

128128
has_session? and not has_csrf?
129129
end
130130

131-
def is_vuln_pipeline?({:pipeline, _, [_name, [do: block]]}, :headers) do
131+
def vuln_pipeline?({:pipeline, _, [_name, [do: block]]}, :headers) do
132132
plugs = get_plug_list(block)
133-
has_headers? = Enum.any?(plugs, &is_plug?(&1, :put_secure_browser_headers))
133+
has_headers? = Enum.any?(plugs, &plug?(&1, :put_secure_browser_headers))
134134
accepts = Enum.find_value(plugs, &get_plug_accepts/1)
135135

136136
!has_headers? && is_list(accepts) && Enum.member?(accepts, "html")
@@ -142,9 +142,9 @@ defmodule Sobelow.Config do
142142

143143
def parse_accepts([{:<<>>, _, [accepts | _]}, []]), do: String.split(accepts, " ")
144144

145-
def is_plug?({:plug, _, [type]}, type), do: true
146-
def is_plug?({:plug, _, [type, _]}, type), do: true
147-
def is_plug?(_, _), do: false
145+
def plug?({:plug, _, [type]}, type), do: true
146+
def plug?({:plug, _, [type, _]}, type), do: true
147+
def plug?(_, _), do: false
148148

149149
def get_fuzzy_configs(key, filepath) do
150150
ast = Parse.ast(filepath)

lib/sobelow/config/csp.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ defmodule Sobelow.Config.CSP do
4646
def check_vuln_pipeline({:pipeline, _, [_name, [do: block]]} = pipeline, meta_file) do
4747
{vuln?, conf, plug} =
4848
Config.get_plug_list(block)
49-
|> Enum.find(&is_header_plug?/1)
49+
|> Enum.find(&header_plug?/1)
5050
|> missing_csp_status(meta_file)
5151

5252
{vuln?, conf, plug, pipeline}
5353
end
5454

55-
defp is_header_plug?({:plug, _, [:put_secure_browser_headers]}), do: true
56-
defp is_header_plug?({:plug, _, [:put_secure_browser_headers, _]}), do: true
57-
defp is_header_plug?(_), do: false
55+
defp header_plug?({:plug, _, [:put_secure_browser_headers]}), do: true
56+
defp header_plug?({:plug, _, [:put_secure_browser_headers, _]}), do: true
57+
defp header_plug?(_), do: false
5858

5959
defp missing_csp_status({_, _, [:put_secure_browser_headers]} = plug, _),
6060
do: {true, :high, plug}

lib/sobelow/config/csrf.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ defmodule Sobelow.Config.CSRF do
2828
finding = Finding.init(@finding_type, Utils.normalize_path(router))
2929

3030
Config.get_pipelines(router)
31-
|> Stream.filter(&is_vuln_pipeline?/1)
31+
|> Stream.filter(&vuln_pipeline?/1)
3232
|> Enum.each(&add_finding(&1, finding))
3333
end
3434

35-
defp is_vuln_pipeline?(pipeline) do
36-
Config.is_vuln_pipeline?(pipeline, :csrf)
35+
defp vuln_pipeline?(pipeline) do
36+
Config.vuln_pipeline?(pipeline, :csrf)
3737
end
3838

3939
defp add_finding({:pipeline, _, [pipeline_name, _]} = pipeline, finding) do

lib/sobelow/config/headers.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ defmodule Sobelow.Config.Headers do
2626
finding = Finding.init(@finding_type, Utils.normalize_path(router))
2727

2828
Config.get_pipelines(router)
29-
|> Stream.filter(&is_vuln_pipeline?/1)
29+
|> Stream.filter(&vuln_pipeline?/1)
3030
|> Enum.each(&add_finding(&1, finding))
3131
end
3232

33-
defp is_vuln_pipeline?(pipeline) do
34-
Config.is_vuln_pipeline?(pipeline, :headers)
33+
defp vuln_pipeline?(pipeline) do
34+
Config.vuln_pipeline?(pipeline, :headers)
3535
end
3636

3737
defp add_finding({:pipeline, _, [pipeline_name, _]} = pipeline, finding) do

lib/sobelow/config/secrets.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule Sobelow.Config.Secrets do
4040

4141
defp enumerate_secrets(secrets, file) do
4242
Enum.each(secrets, fn {fun, key, val} ->
43-
if is_binary(val) && String.length(val) > 0 && !is_env_var?(val) do
43+
if is_binary(val) && String.length(val) > 0 && !env_var?(val) do
4444
add_finding(file, Parse.get_fun_line(fun), fun, key, val)
4545
end
4646
end)
@@ -49,18 +49,18 @@ defmodule Sobelow.Config.Secrets do
4949
defp enumerate_fuzzy_secrets(secrets, file) do
5050
Enum.each(secrets, fn {fun, vals} ->
5151
Enum.each(vals, fn {k, v} ->
52-
if is_binary(v) && String.length(v) > 0 && !is_env_var?(v) do
52+
if is_binary(v) && String.length(v) > 0 && !env_var?(v) do
5353
add_finding(file, Parse.get_fun_line(fun), fun, k, v)
5454
end
5555
end)
5656
end)
5757
end
5858

59-
def is_env_var?("${" <> rest) do
59+
def env_var?("${" <> rest) do
6060
String.ends_with?(rest, "}")
6161
end
6262

63-
def is_env_var?(_), do: false
63+
def env_var?(_), do: false
6464

6565
defp add_finding(file, line_no, fun, key, val) do
6666
{vuln_line_no, vuln_line_col} = get_vuln_line(file, line_no, val)

lib/sobelow/dos/binary_to_atom.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.DOS.BinToAtom do
1717
use Sobelow.Finding
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Finding.init(@finding_type, meta_file.filename, confidence)
2323
|> Finding.multi_from_def(fun, parse_def(fun))

lib/sobelow/dos/list_to_atom.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.DOS.ListToAtom do
1717
use Sobelow.Finding
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Finding.init(@finding_type, meta_file.filename, confidence)
2323
|> Finding.multi_from_def(fun, parse_def(fun))

lib/sobelow/dos/string_to_atom.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.DOS.StringToAtom do
1717
use Sobelow.Finding
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Finding.init(@finding_type, meta_file.filename, confidence)
2323
|> Finding.multi_from_def(fun, parse_def(fun))

lib/sobelow/parse.ex

+8-8
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ defmodule Sobelow.Parse do
681681

682682
reflected_vars =
683683
Enum.filter(vars, fn var ->
684-
(is_reflected_var?(var) && is_in_params?(var, params)) || is_conn_params?(var)
684+
(reflected_var?(var) && in_params?(var, params)) || conn_params?(var)
685685
end)
686686

687687
var_keys =
@@ -705,16 +705,16 @@ defmodule Sobelow.Parse do
705705
end
706706
end
707707

708-
defp is_reflected_var?({_, {_, _, nil}}), do: true
709-
defp is_reflected_var?(_), do: false
708+
defp reflected_var?({_, {_, _, nil}}), do: true
709+
defp reflected_var?(_), do: false
710710

711-
defp is_in_params?({_, {var, _, _}}, params) do
711+
defp in_params?({_, {var, _, _}}, params) do
712712
Enum.member?(params, var)
713713
end
714714

715-
def is_conn_params?({_, {{:., _, [Access, :get]}, _, access_opts}}),
716-
do: is_conn_params?(access_opts)
715+
def conn_params?({_, {{:., _, [Access, :get]}, _, access_opts}}),
716+
do: conn_params?(access_opts)
717717

718-
def is_conn_params?([{{:., _, [{:conn, _, nil}, :params]}, _, []}, _]), do: true
719-
def is_conn_params?(_), do: false
718+
def conn_params?([{{:., _, [{:conn, _, nil}, :params]}, _, []}, _]), do: true
719+
def conn_params?(_), do: false
720720
end

lib/sobelow/rce/code_module.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule Sobelow.RCE.CodeModule do
2222
@code_funs [:eval_string, :eval_file, :eval_quoted]
2323

2424
def run(fun, meta_file) do
25-
confidence = if !meta_file.is_controller?, do: :low
25+
confidence = if !meta_file.controller?, do: :low
2626

2727
Enum.each(@code_funs, fn code_fun ->
2828
"RCE.CodeModule: Code Execution in `Code.#{code_fun}`"

lib/sobelow/rce/eex.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.RCE.EEx do
1717
@eex_funs [:eval_string, :eval_file]
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Enum.each(@eex_funs, fn eex_fun ->
2323
"RCE.EEx: Code Execution in `EEx.#{eex_fun}`"

lib/sobelow/sql/query.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule Sobelow.SQL.Query do
1919
use Sobelow.Finding
2020

2121
def run(fun, meta_file) do
22-
confidence = if !meta_file.is_controller?, do: :low
22+
confidence = if !meta_file.controller?, do: :low
2323

2424
Enum.each(@query_funcs, fn query_func ->
2525
Finding.init(@finding_type, meta_file.filename, confidence)

lib/sobelow/sql/stream.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.SQL.Stream do
1717
use Sobelow.Finding
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Finding.init(@finding_type, meta_file.filename, confidence)
2323
|> Finding.multi_from_def(fun, parse_sql_def(fun))

lib/sobelow/traversal/file_module.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule Sobelow.Traversal.FileModule do
4040
@double_file_funcs [:cp, :copy, :cp!, :copy!, :cp_r, :cp_r!, :ln, :ln!, :ln_s, :ln_s!]
4141

4242
def run(fun, meta_file) do
43-
confidence = if !meta_file.is_controller?, do: :low
43+
confidence = if !meta_file.controller?, do: :low
4444

4545
Enum.each(@file_funcs ++ @double_file_funcs, fn file_func ->
4646
"Traversal.FileModule: Directory Traversal in `File.#{file_func}`"

lib/sobelow/traversal/send_download.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.Traversal.SendDownload do
1717
use Sobelow.Finding
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Finding.init(@finding_type, meta_file.filename, confidence)
2323
|> Finding.multi_from_def(fun, parse_def(fun))

lib/sobelow/traversal/send_file.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Sobelow.Traversal.SendFile do
1717
use Sobelow.Finding
1818

1919
def run(fun, meta_file) do
20-
confidence = if !meta_file.is_controller?, do: :low
20+
confidence = if !meta_file.controller?, do: :low
2121

2222
Finding.init(@finding_type, meta_file.filename, confidence)
2323
|> Finding.multi_from_def(fun, parse_def(fun))

lib/sobelow/utils.ex

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ defmodule Sobelow.Utils do
33

44
alias Sobelow.Parse
55

6-
def is_controller?(uses) do
6+
def controller?(uses) do
77
has_use_type?(uses, :controller)
88
end
99

10-
def is_router?(uses) do
10+
def router?(uses) do
1111
has_use_type?(uses, :router)
1212
end
1313

14-
def is_endpoint?([{:use, _, [{_, _, [:Phoenix, :Endpoint]}, _]} | _]), do: true
15-
def is_endpoint?([_ | t]), do: is_endpoint?(t)
16-
def is_endpoint?(_), do: false
14+
def endpoint?([{:use, _, [{_, _, [:Phoenix, :Endpoint]}, _]} | _]), do: true
15+
def endpoint?([_ | t]), do: endpoint?(t)
16+
def endpoint?(_), do: false
1717

1818
def has_use_type?([{:use, _, [_, type]} | _], type), do: true
1919
def has_use_type?([_ | t], type), do: has_use_type?(t, type)

lib/sobelow/xss.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule Sobelow.XSS do
3030

3131
def get_vulns(fun, meta_file, web_root, skip_mods \\ []) do
3232
controller =
33-
if meta_file.is_controller? do
33+
if meta_file.controller? do
3434
String.replace_suffix(meta_file.filename, "_controller.ex", "")
3535
|> Path.basename()
3636
end

lib/sobelow/xss/content_type.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defmodule Sobelow.XSS.ContentType do
2727
use Sobelow.Finding
2828

2929
def run(fun, meta_file) do
30-
confidence = if !meta_file.is_controller?, do: :low
30+
confidence = if !meta_file.controller?, do: :low
3131

3232
Finding.init(@finding_type, meta_file.filename, confidence)
3333
|> Finding.multi_from_def(fun, parse_def(fun))

0 commit comments

Comments
 (0)