Repository navigation
feat: redact encryption key pragmas in trace logs - #1501
Merged
Merged
Conversation
Mask the value of the key, hexkey, textkey, rekey, hexrekey and textrekey pragmas in the [SQLite EXEC] trace output, so the connection password is not written to the logs. The redaction runs inside the log supplier, so it has no cost when TRACE is disabled. The executed SQL is unchanged. Closes xerial#1482
Collaborator
|
Thanks for the PR! |
|
thanks a lot @hsdfat (NB: I had a local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1482
When TRACE logging is on,
NativeDBlogs every statement it executes or prepares as[SQLite EXEC] .... For encrypted databases that includespragma key = '...'(for example the one issued from thepasswordproperty), so the key ended up in the log in plain text.What changed, all in
NativeDB.java:key,hexkey,textkey,rekey,hexrekeyandtextrekeypragmas, in both thepragma key = valueandpragma key(value)forms. It allows an optional schema prefix and quoted or bare values, and uses possessive quantifiers so a very long quoted value cannot overflow the regex stack.redactSecrets(String)that replaces the value with'***'. It keeps the pragma name and any statements that follow, and returns null for null.[SQLite EXEC]trace messages (in_execandprepare) now logredactSecrets(sql). This runs inside the log supplier, so nothing extra happens when TRACE is off.Only the
pragmaforms are covered. SQLCipher'sATTACH ... KEY '...'is not redacted.Tests, in the new
NativeDBTraceLogTest:redactSecretsHidesKeyValue(parameterized, 9 cases)redactSecretsKeepsPragmaNameAndFollowingStatementsredactSecretsLeavesOtherStatementsUnchanged(parameterized, 4 cases)redactSecretsHandlesNullredactSecretsHandlesVeryLongKey(an 800k-character quoted key; a plain(?:[^']|'')*pattern throwsStackOverflowErrorhere)traceLogDoesNotContainPasswordopens a connection with thepasswordproperty, runspragma rekey, and checks that neither secret shows up in the TRACE output while the'***'lines do.traceLogDoesNotContainPasswordfails without the fix. With the old logging, the trace output containspragma key = 'supersecret'.NativeDBTraceLogTest,CodingRulesTestandSQLiteConfigTestpass locally, andspotless:checkpasses.