Skip to content

Commit

Permalink
make sure to filter authorization headers
Browse files Browse the repository at this point in the history
closes #274
  • Loading branch information
beniwohli committed Aug 29, 2018
1 parent e8b134d commit 8201c1f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion elasticapm/processors.py
Expand Up @@ -17,7 +17,9 @@

MASK = 8 * "*"

SANITIZE_FIELD_NAMES = frozenset(["password", "secret", "passwd", "token", "api_key", "access_token", "sessionid"])
SANITIZE_FIELD_NAMES = frozenset(
["authorization", "password", "secret", "passwd", "token", "api_key", "access_token", "sessionid"]
)

SANITIZE_VALUE_PATTERNS = [re.compile(r"^[- \d]{16,19}$")] # credit card numbers, with or without spacers

Expand Down
17 changes: 15 additions & 2 deletions tests/processors/tests.py
Expand Up @@ -15,7 +15,13 @@ def http_test_data():
"request": {
"body": "foo=bar&password=123456&the_secret=abc&cc=1234567890098765",
"env": {"foo": "bar", "password": "hello", "the_secret": "hello", "a_password_here": "hello"},
"headers": {"foo": "bar", "password": "hello", "the_secret": "hello", "a_password_here": "hello"},
"headers": {
"foo": "bar",
"password": "hello",
"the_secret": "hello",
"a_password_here": "hello",
"authorization": "bearer xyz",
},
"cookies": {
"foo": "bar",
"password": "topsecret",
Expand All @@ -30,7 +36,13 @@ def http_test_data():
},
"response": {
"status_code": "200",
"headers": {"foo": "bar", "password": "hello", "the_secret": "hello", "a_password_here": "hello"},
"headers": {
"foo": "bar",
"password": "hello",
"the_secret": "hello",
"a_password_here": "hello",
"authorization": "bearer xyz",
},
},
}
}
Expand Down Expand Up @@ -111,6 +123,7 @@ def test_sanitize_http_headers(http_test_data):
"password": processors.MASK,
"the_secret": processors.MASK,
"a_password_here": processors.MASK,
"authorization": processors.MASK,
}
assert result["context"]["request"]["headers"] == expected
assert result["context"]["response"]["headers"] == expected
Expand Down

0 comments on commit 8201c1f

Please sign in to comment.