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

Make compiling SQL in error message optional #5282

Merged
merged 5 commits into from Sep 23, 2022

Conversation

JakobJoonas
Copy link
Contributor

@JakobJoonas JakobJoonas commented Jul 28, 2022

Hello!

Description
Currently the only and default behaviour of Knex is to add compiled SQL query into the error message, while it is good for debugging and visibility purposes, it also has a major drawback that it may leak sensitive information to logs.

Changes

  • Created a new configuration option: compileSqlOnError (Documentation PR).
  • When compileSqlOnError is true, then compiled SQL will be added to error, otherwise parameterized SQL will be added

Default value
By default the parameterized SQL will be added to the error message instead of the compiled SQL as it is now. Why did I make it default to parameterized? Because not having compiled SQL come up in error messages by default seems to be a much safer option, as it avoids leaking sensitive information to the logs, If a developer needs to debug anything then there is always the option to turn it on by enabling compileSqlOnError

Extra notes
Please let me know if you have any remarks about this and if you think the default behaviour should be the opposite, I'm sure we can find a way integrate this option into Knex as this is something that can save leaking someones information.

Copy link
Collaborator

@OlivierCavadenti OlivierCavadenti left a comment

Choose a reason for hiding this comment

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

perfect, thx for the PR

Copy link
Collaborator

@OlivierCavadenti OlivierCavadenti left a comment

Choose a reason for hiding this comment

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

seems good for me, but I think we need to set this boolean to true by default no ? to have same behavior that before, or need to fix tests

@kibertoad
Copy link
Collaborator

it would be a semver major if default is "no"

@coveralls
Copy link

coveralls commented Jul 30, 2022

Coverage Status

Coverage increased (+0.007%) to 92.334% when pulling 83d18cd on JakobJoonas:hide-sensitive-data into dc6dbbf on knex:master.

@JakobJoonas
Copy link
Contributor Author

JakobJoonas commented Aug 1, 2022

Thanks for the answer, here I'd like to get your feedback about this.

I would prefer it to be "no" as default because it is a much safer option and when I get your validation about this I can update the tests to not fail. However I do understand that this requires a major version increase, I have not contributed a lot to open source projects, would I have to do anything to make the major version happen or is this part handled by the maintainers?

@JakobJoonas
Copy link
Contributor Author

@kibertoad or @OlivierCavadenti what would you think about making this a major upgrade as mentioned above?

@JakobJoonas
Copy link
Contributor Author

Okay, to move on with this, I made the field to be true as default, so no major upgrade would be needed, but this is something that I think should be though of with the next major upgrade :)

@OlivierCavadenti
Copy link
Collaborator

hi, seems you still have one test fail on postgres.

@JakobJoonas
Copy link
Contributor Author

Indeed it was, tests had a bit different setup, should be fixed now, tests pass on local machine

Copy link
Collaborator

@OlivierCavadenti OlivierCavadenti left a comment

Choose a reason for hiding this comment

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

@JakobJoonas Thanks and sorry again for the delay.
Can you check that merged documentation is ok in knex/documentation repo since you change init value for the boolean ?

@JakobJoonas
Copy link
Contributor Author

@OlivierCavadenti Thanks for reminding that, created a PR: knex/documentation#463

@samad123qQQ
Copy link

seems good for me, but I think we need to set this boolean to true by default no ? to have same behavior that before, or need to fix tests

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.

None yet

5 participants