Skip to content

Commit

Permalink
filter passwords in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
srivathsanmurali authored and minijackson committed Feb 16, 2020
1 parent 2ae4e8e commit 465860e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ config :paddle, Paddle,
host: "ldap.my-organisation.org",
base: "dc=myorganisation,dc=org",
ssl: true,
port: 636
port: 636,
filter_passwords: true

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
Expand Down
14 changes: 12 additions & 2 deletions lib/paddle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ defmodule Paddle do
sslopts: [certfile: '/path/to/certificate.crt'],
timeout: 3000,
account_subdn: "ou=People",
schema_files: Path.wildcard("/etc/openldap/schema/*.schema")
schema_files: Path.wildcard("/etc/openldap/schema/*.schema"),
filter_passwords: true
Option | Description | Default
--------- | ----------- | -------
Expand All @@ -32,6 +33,7 @@ defmodule Paddle do
`:account_subdn` | The DN (without the base) where the accounts are located. Used by the `Paddle.authenticate/2` function. | `"ou=People"`
`:account_identifier` | The identifier by which users are identified. Used by the `Paddle.authenticate/2` function. | `:uid`
`:schema_files` | Files which are to be parsed to help generate classes using [`Paddle.Class.Helper`](Paddle.Class.Helper.html#module-using-schema-files). | `[]`
`:filter_passwords` | Filter passwords from appearing in the logs | `true`
## Usage
Expand Down Expand Up @@ -676,7 +678,15 @@ defmodule Paddle do

@doc false
def eldap_log_callback(level, format_string, format_args) do
message = :io_lib.format(format_string, format_args)
message = case Application.get_env(:paddle, :filter_passwords, true) do
true ->
:io_lib.format(format_string, format_args)
|> to_string()
|> String.replace(~r/{simple,".*"}/, ~s({simple,"filtered"}))
false ->
:io_lib.format(format_string, format_args)
end

case level do
# Level 1 seems unused by :eldap
1 -> Logger.info(message)
Expand Down

0 comments on commit 465860e

Please sign in to comment.