-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by simahawk
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import test_webservice | ||
from . import test_utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2023 Camptocamp SA | ||
# @author Simone Orsi <simahawk@gmail.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from odoo.tests.common import BaseCase | ||
|
||
from odoo.addons.webservice.utils import sanitize_url_for_log | ||
|
||
|
||
class TestUtils(BaseCase): | ||
def test_url_cleanup(self): | ||
url = "https://custom.url/?a=1&apikey=secret&password=moresecret" | ||
self.assertEqual(sanitize_url_for_log(url), "https://custom.url/?a=1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2023 Camptocamp SA | ||
# @author Simone Orsi <simahawk@gmail.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse | ||
|
||
|
||
def sanitize_url_for_log(url, blacklisted_keys=None): | ||
"""Sanitize url to avoid loggin sensitive data""" | ||
blacklisted_keys = blacklisted_keys or ("apikey", "password", "pwd") | ||
parsed = urlparse(url) | ||
query = parse_qs(parsed.query, keep_blank_values=False) | ||
clean_query = {} | ||
|
||
def is_blacklisted(k): | ||
for bl_key in blacklisted_keys: | ||
if bl_key.lower() in k.lower(): | ||
return True | ||
|
||
for k, v in query.items(): | ||
if not is_blacklisted(k): | ||
clean_query[k] = v | ||
|
||
parsed = parsed._replace(query=urlencode(clean_query, True)) | ||
return urlunparse(parsed) |