Skip to content

Store query params in driver exceptions #4387

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

Merged
merged 1 commit into from
Nov 1, 2020

Conversation

BenMorel
Copy link
Contributor

Q A
Type improvement
BC Break no
Fixed issues none

Summary

This is an attempt at #4325 (comment).

This PR removes the text representation of the bound parameters in the query exception message, and stores these params together with their types in the DriverException instead. This shifts the responsibility of (not) storing/displaying bound parameters explicitly to the consumer of the exception.

Just like #4325, this removes the dependency on ext-json (plus a couple lines of code!).

@BenMorel
Copy link
Contributor Author

Oops, after running Psalm, I realized that DriverException is marked as immutable. I cannot easily change this as it cascades to other errors, which makes me believe that you do want to keep exceptions immutable.

Thus I only see 2 solutions:

  • pass the params & types down to the ExceptionConverter and back to the DriverException; this would be really cumbersome but would work;
  • change setQueryParams() and setQueryParamTypes() to withQueryParams(), that returns a copy of the exception; I've tried this path in 4ee8fe1 but the exception being uncloneable, this makes the implementation a bit of a mess: I had to suppress phpstan & psalm warnings, so I can't say I'm happy with this.

@BenMorel
Copy link
Contributor Author

@morozov Please check this new version!

Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're moving in the right direction.

@morozov
Copy link
Member

morozov commented Oct 26, 2020

@beberlei do you think we could include this into 3.0 instead of master? While it changes the behavior many developers may be used to, it reduces the possibility of leaking sensitive data by the DBAL which cannot be fixed w/o a BC break.

Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic-wise looks good to me, only the upgrade notes are missing. Could you try to retarget against 3.0.x?

{
if ($query !== null) {
$message = 'An exception occurred while executing the query: ' . $driverException->getMessage();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure which "the query" is being referred to since there's no query in the context. @greg0ire what would be the proper wording?

@morozov
Copy link
Member

morozov commented Oct 27, 2020

@doctrine/team-dbal, please be informed. With this change, the query and its parameters will be no longer part of the exception message but will be accessible via DriverException::getQuery(). It will help prevent leaking potentially sensitive data to logs, etc. but will require changes in the tooling to display these bits during development.

@BenMorel BenMorel changed the base branch from master to 3.0.x October 27, 2020 15:55
@BenMorel
Copy link
Contributor Author

@morozov Rebased on 3.0.x, waiting for feedback on wording!

@morozov
Copy link
Member

morozov commented Oct 28, 2020

@BenMorel I believe the wording is not that critical but the upgrade notes are still missing.

@BenMorel
Copy link
Contributor Author

@morozov Done!

By the way, shouldn't ExceptionConverter and DriverException::__construct() be internal?

@morozov
Copy link
Member

morozov commented Oct 29, 2020

By the way, shouldn't ExceptionConverter and DriverException::__construct() be internal?

That would make sense, I think. I believe all exception constructors should be internal (not in this patch) since only the DBAL is supposed to instantiate them.

@BenMorel
Copy link
Contributor Author

That would make sense, I think. I believe all exception constructors should be internal (not in this patch) since only the DBAL is supposed to instantiate them.

Should I make at least these 2 @internal? Or we'll have to revert the changelog later.

@morozov
Copy link
Member

morozov commented Oct 29, 2020

Should I make at least these 2 @internal? Or we'll have to revert the changelog later.

Yeah, let's do, and update the upgrade notes accordingly. The wording changes look good to me as well, so it may be also the time to squash everything.

@BenMorel
Copy link
Contributor Author

@morozov Done!

Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. I misread your question in #4387 (comment) and thought you were asking about constructors in both cases.

@BenMorel
Copy link
Contributor Author

@morozov I fixed this in 06732c5, please let me know if everything's ok now and I'll squash.

@morozov
Copy link
Member

morozov commented Oct 30, 2020

Looks good.

@BenMorel
Copy link
Contributor Author

Squashed!

morozov
morozov previously approved these changes Oct 30, 2020
@morozov morozov added this to the 3.0.0 milestone Oct 30, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
marandaneto Manoel Aranda Neto
@morozov morozov merged commit 83113ce into doctrine:3.0.x Nov 1, 2020
@morozov
Copy link
Member

morozov commented Nov 1, 2020

Thanks, @BenMorel!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants