You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Aditya-kumar-yadav (via GitHub)" <gi...@apache.org> on 2026/10/20 13:10:01 UTC
[PR] Fix URI credential masking in CLI connection display [airflow]
Aditya-kumar-yadav opened a new pull request, #75215:
URL: https://github.com/apache/airflow/pull/75215
When displaying connection details with sensitive values masked (`airflow connections get` and `connections list --show-values --hide-sensitive`), `_mask_uri_credentials` previously split `netloc` on the first `@`.
This led to two bugs:
1. **Password leakage**: If a URI password contains an `@` character (e.g. `postgresql://user:p@ssword@host:5432/db`), splitting on the first `@` caused `_creds` to receive only `user:p` and `host_port` to receive `ssword@host:5432`. Consequently, the remainder of the cleartext password (`ssword`) was printed in the host portion of the masked URI. Splitting from the right with `rsplit("@", 1)` ensures all userinfo before the host is properly isolated.
2. **Artificial password injection**: When a URI contained only a username or token without a password (e.g. `ssh://git@host:22/repo`), the function unconditionally formatted `f"{SENSITIVE_PLACEHOLDER}:{SENSITIVE_PLACEHOLDER}@{host_port}"`, injecting an artificial `:***` password field where none was present. It now preserves whether username-only, password-only, or user-and-password credentials are provided.
Added unit test cases to `TestUriMasking` in `test_connection_command.py` covering passwords containing `@`, username-only credentials, password-only credentials, empty passwords, and userinfo with colons.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Antigravity
Generated-by: Antigravity following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix URI credential masking in CLI connection display [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #75215:
URL: https://github.com/apache/airflow/pull/75215#issuecomment-6291619566
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our [Contributors' Guide](https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-prek-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example Dag that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
- Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
Apache Airflow is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix URI credential masking in CLI connection display [airflow]
Posted by "Aditya-kumar-yadav (via GitHub)" <gi...@apache.org>.
Aditya-kumar-yadav commented on PR #75215:
URL: https://github.com/apache/airflow/pull/75215#issuecomment-6294019595
Thanks for reviewing @Eason09053360! You are completely right — `Connection.get_uri()` percent-encodes the password, so `@` in the password becomes `%40`.
I have updated the PR accordingly:
1. Updated the tests to test `Connection(...).get_uri()` directly across the different credential configurations (user+password, username-only, password-only token, empty password, no credentials).
2. Updated the PR description and commit message to drop the leak claim and focus on preserving credential structure (avoiding artificial `:***` injection for username-only/token connections).
Pushed the updated commit!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix URI credential masking in CLI connection display [airflow]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #75215:
URL: https://github.com/apache/airflow/pull/75215#discussion_r4327867773
##########
airflow-core/tests/unit/cli/commands/test_connection_command.py:
##########
@@ -181,23 +181,124 @@ def test_cli_connections_list_does_not_warn_by_default(self, monkeypatch):
class TestUriMasking:
"""Test URI credential masking functionality."""
+ @pytest.mark.parametrize(
+ ("conn", "expected"),
+ [
+ # Full credentials (user and password)
+ (
+ Connection(
+ conn_id="c1",
+ conn_type="postgresql",
+ host="host",
+ port=5432,
+ schema="db",
+ login="user",
+ password="pass",
+ ),
+ "postgresql://***:***@host:5432/db",
+ ),
+ (
+ Connection(
+ conn_id="c2",
+ conn_type="mysql",
+ host="localhost",
+ port=3306,
+ schema="test",
+ login="admin",
+ password="secret",
+ ),
+ "mysql://***:***@localhost:3306/test",
+ ),
+ (
+ Connection(
+ conn_id="c3",
+ conn_type="http",
+ host="api.example.com",
+ port=8080,
+ schema="v1",
+ login="api",
+ password="key123",
+ ),
+ "http://***:***@api.example.com:8080/v1",
+ ),
+ (
+ Connection(
+ conn_id="c4",
+ conn_type="postgresql",
+ host="host",
+ port=5432,
+ schema="db",
+ login="user",
+ password="p@ssword",
+ ),
+ "postgresql://***:***@host:5432/db",
+ ),
+ # Username only
+ (
+ Connection(
+ conn_id="c5",
+ conn_type="ssh",
+ host="github.com",
+ port=22,
+ schema="repo",
+ login="git",
+ ),
+ "ssh://***@github.com:22/repo",
+ ),
+ # Password only (token)
+ (
+ Connection(
+ conn_id="c6",
+ conn_type="http",
+ host="api.example.com",
+ password="secret_token",
+ ),
+ "http://:***@api.example.com",
+ ),
+ # Empty password (user:)
+ (
+ Connection(
+ conn_id="c7",
+ conn_type="http",
+ host="api.example.com",
+ login="user",
+ password="",
+ ),
+ "http://***:@api.example.com",
Review Comment:
This expectation fails: `FernetFieldsMixin.set_password()` ignores empty strings (`models/crypto.py:116–121`), leaving this connection's password as `None`. `get_uri()` therefore emits `http://user@api.example.com`, which is correctly masked without a colon. Expect the username-only result here; preservation of an explicit empty password needs a literal URI case in the URI-based tests.
##########
airflow-core/tests/unit/cli/commands/test_connection_command.py:
##########
@@ -181,23 +181,124 @@ def test_cli_connections_list_does_not_warn_by_default(self, monkeypatch):
class TestUriMasking:
"""Test URI credential masking functionality."""
+ @pytest.mark.parametrize(
+ ("conn", "expected"),
+ [
+ # Full credentials (user and password)
+ (
+ Connection(
+ conn_id="c1",
+ conn_type="postgresql",
+ host="host",
+ port=5432,
+ schema="db",
+ login="user",
+ password="pass",
+ ),
+ "postgresql://***:***@host:5432/db",
+ ),
+ (
+ Connection(
+ conn_id="c2",
+ conn_type="mysql",
+ host="localhost",
+ port=3306,
+ schema="test",
+ login="admin",
+ password="secret",
+ ),
+ "mysql://***:***@localhost:3306/test",
+ ),
+ (
+ Connection(
+ conn_id="c3",
+ conn_type="http",
+ host="api.example.com",
+ port=8080,
+ schema="v1",
+ login="api",
+ password="key123",
+ ),
+ "http://***:***@api.example.com:8080/v1",
+ ),
+ (
+ Connection(
+ conn_id="c4",
+ conn_type="postgresql",
+ host="host",
+ port=5432,
+ schema="db",
+ login="user",
+ password="p@ssword",
+ ),
+ "postgresql://***:***@host:5432/db",
+ ),
+ # Username only
+ (
+ Connection(
+ conn_id="c5",
+ conn_type="ssh",
+ host="github.com",
+ port=22,
+ schema="repo",
+ login="git",
+ ),
+ "ssh://***@github.com:22/repo",
+ ),
+ # Password only (token)
+ (
+ Connection(
+ conn_id="c6",
+ conn_type="http",
+ host="api.example.com",
+ password="secret_token",
+ ),
+ "http://:***@api.example.com",
+ ),
+ # Empty password (user:)
+ (
+ Connection(
+ conn_id="c7",
+ conn_type="http",
+ host="api.example.com",
+ login="user",
+ password="",
+ ),
+ "http://***:@api.example.com",
+ ),
+ # Connections without credentials
+ (
+ Connection(
+ conn_id="c8",
+ conn_type="http",
+ host="example.com",
+ ),
+ "http://example.com",
+ ),
+ (
+ Connection(
+ conn_id="c9",
+ conn_type="redis",
+ host="localhost",
+ port=6379,
+ schema="0",
+ ),
+ "redis://localhost:6379/0",
+ ),
+ ],
+ )
+ def test_mask_uri_credentials_from_connection(self, conn, expected):
+ result = _mask_uri_credentials(conn.get_uri())
+ assert result == expected
+
@pytest.mark.parametrize(
("uri", "expected"),
[
- # URIs with credentials
- ("postgresql://user:pass@host:5432/db", "postgresql://***:***@host:5432/db"),
- ("mysql://admin:secret@localhost:3306/test", "mysql://***:***@localhost:3306/test"),
- ("http://api:key123@api.example.com:8080/v1", "http://***:***@api.example.com:8080/v1"),
- # URIs without credentials
- ("sqlite:///tmp/test.db", "sqlite:///tmp/test.db"),
- ("filesystem://", "filesystem://"),
- ("redis://localhost:6379/0", "redis://localhost:6379/0"),
- # Edge cases
("", ""),
("invalid-uri", "***"), # Falls back to full masking on parse error
Review Comment:
The last-`@` split and empty-userinfo return lack regression coverage. `Connection.get_uri()` percent-encodes credential `@` characters, so the `p@ssword` fixture also passes with the old first-`@` split. It also omits the password separator for the empty-string fixture. Add literal URI cases for multiple `@` characters, empty userinfo, and an explicit empty password to exercise these changed paths.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org