Skip to content

Commit

Permalink
socketutil: 'safe' functions for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hius07 authored Feb 11, 2025
1 parent 2e893f5 commit 6769d35
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frontend/socketutil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,38 @@ function socketutil.file_sink(handle, io_err)
end
end

function socketutil.safe_headers(headers)
local sensitive_headers = {
["authorization"] = true,
["cookie"] = true,
["proxy-authorization"] = true,
["set-cookie"] = true,
}
local safe_headers = {}
for key, value in pairs(headers) do
if sensitive_headers[key] then
safe_headers[key] = "REDACTED"
else
safe_headers[key] = value
end
end
return safe_headers
end

function socketutil.safe_request(request)
local sensitive_props = {
["password"] = true,
["user"] = true,
}
local safe_request = {}
for key, value in pairs(request) do
if sensitive_props[key] then
safe_request[key] = "REDACTED"
else
safe_request[key] = value
end
end
return safe_request
end

return socketutil

0 comments on commit 6769d35

Please sign in to comment.