Skip to content

Commit 805473d

Browse files
Sanitise password in logs while parsing connection from URI (#62180)
Co-authored-by: Stephen Bracken <email-protected>
1 parent 49ea0a2 commit 805473d

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

airflow-core/src/airflow/models/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _normalize_conn_type(conn_type):
226226
def _parse_from_uri(self, uri: str):
227227
schemes_count_in_uri = uri.count("://")
228228
if schemes_count_in_uri > 2:
229-
raise AirflowException(f"Invalid connection string: {uri}.")
229+
raise AirflowException("Invalid connection string.")
230230
host_with_protocol = schemes_count_in_uri == 2
231231
uri_parts = urlsplit(uri)
232232
conn_type = uri_parts.scheme
@@ -235,7 +235,7 @@ def _parse_from_uri(self, uri: str):
235235
if host_with_protocol:
236236
uri_splits = rest_of_the_url.split("://", 1)
237237
if "@" in uri_splits[0] or ":" in uri_splits[0]:
238-
raise AirflowException(f"Invalid connection string: {uri}.")
238+
raise AirflowException("Invalid connection string.")
239239
uri_parts = urlsplit(rest_of_the_url)
240240
protocol = uri_parts.scheme if host_with_protocol else None
241241
host = _parse_netloc_to_hostname(uri_parts)

airflow-core/tests/unit/models/test_connection.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def clear_fernet_cache(self):
138138
{"param": "value"},
139139
None,
140140
),
141-
(
141+
( # Test password sanitisation
142142
"type://user:pass@protocol://host:port?param=value",
143143
None,
144144
None,
@@ -147,7 +147,29 @@ def clear_fernet_cache(self):
147147
None,
148148
None,
149149
None,
150-
r"Invalid connection string: type://user:pass@protocol://host:port?param=value.",
150+
r"Invalid connection string.",
151+
),
152+
(
153+
"foo:pwd@host://://",
154+
None,
155+
None,
156+
None,
157+
None,
158+
None,
159+
None,
160+
None,
161+
r"Invalid connection string.",
162+
),
163+
(
164+
"type://:foo@host/://://",
165+
None,
166+
None,
167+
None,
168+
None,
169+
None,
170+
None,
171+
None,
172+
r"Invalid connection string.",
151173
),
152174
(
153175
"type://host?int_param=123&bool_param=true&float_param=1.5&str_param=some_str",

0 commit comments

Comments
 (0)