Skip to content

Commit

Permalink
Merge pull request #109 from RelationalAI/axb-reporting-showerror
Browse files Browse the repository at this point in the history
Reporting `showerror`
  • Loading branch information
bergel authored Dec 2, 2024
2 parents f631066 + 52cd3c3 commit 040fcb3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/linting/extended_checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ struct InterpolationInSafeLogRule <: RecommendationLintRule end
struct UseOfStaticThreads <: ViolationLintRule end
struct LogStatementsMustBeSafe <: FatalLintRule end

struct ShowErrorReporting <: RecommendationLintRule end

const all_extended_rule_types = Ref{Any}(
vcat(
InteractiveUtils.subtypes(RecommendationLintRule),
Expand Down Expand Up @@ -585,3 +587,8 @@ function check(t::LogStatementsMustBeSafe, x::EXPR)
end
end

function check(t::ShowErrorReporting, x::EXPR)
msg = "Reporting with `showerror(...)` instead of `safe_showerror(...)` could leak sensitive data."
# generic_check(t, x, "showerror(hole_variable_star)", msg)
generic_check(t, x, "showerror", msg)
end
19 changes: 17 additions & 2 deletions test/rai_rules_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,7 @@ end
precompile_statement=@safe(repr(statement)),
# Log the message that the exception would print, else JSONLogger logs each of
# the fields of the exception separately which is much less useful.
exception=@safe(sprint(showerror, e)),
exception=@safe(sprint(show, e)),
maxlog=100,
)
end
Expand Down Expand Up @@ -2027,4 +2027,19 @@ end
end
@test result_matching
end
end
end

@testset "showerror reporting" begin
source = """
function rusage()
showerror("an error")
map(showerror, ["a", "b"]);
safe_showerror("an error")
end
"""
@test count_lint_errors(source) == 2
@test lint_test(source,
"Line 2, column 5: Reporting with `showerror(...)` instead of `safe_showerror(...)` could leak sensitive data.")
@test lint_test(source,
"Line 3, column 9: Reporting with `showerror(...)` instead of `safe_showerror(...)` could leak sensitive data.")
end

0 comments on commit 040fcb3

Please sign in to comment.