Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Mask MotherDuck connection token in the logs #3875

Merged
merged 6 commits into from
Feb 21, 2025

Conversation

themisvaltinos
Copy link
Contributor

Mask the MotherDuck connection token in logs, displaying it as asterisks (md:db?motherduck_token=************) instead of revealing the actual value.

@izeigerman
Copy link
Member

I believe there's another place where we leak tokens into logs:

if isinstance(path_options, DuckDBAttachOptions):
query = path_options.to_sql(alias)
else:
query = f"ATTACH '{path_options}'"
if not path_options.startswith("md:"):
query += f" AS {alias}"
elif self.token:
query += f"?motherduck_token={self.token}"
cursor.execute(query)

The ATTACH statement contains a token and this is statement is happily logged by the engine adapter.

@themisvaltinos
Copy link
Contributor Author

I believe there's another place where we leak tokens into logs:

elif self.token:
query += f"?motherduck_token={self.token}"
cursor.execute(query)

The ATTACH statement contains a token and this is statement is happily logged by the engine adapter.

If I'm not mistaken we do not log this since this is the DuckDBPyConnection's execute method. Or is this being logged somewhere internally?

@izeigerman
Copy link
Member

@themisvaltinos ah, great point. I think you're right

@georgesittas
Copy link
Contributor

georgesittas commented Feb 21, 2025

Update: I realized this is inconsistent with the other config classes, where password etc are not masked in __str__ and __repr__. Apologies for the back and forth, that probably wasn't a great suggestion.

I think we can just revert the last commit and simply factor out the regex at the top of the file so it's compiled once. Then it should be good to go.

@themisvaltinos themisvaltinos merged commit 4222e27 into main Feb 21, 2025
21 checks passed
@themisvaltinos themisvaltinos deleted the themis/mdtoken_log branch February 21, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants