-
-
Notifications
You must be signed in to change notification settings - Fork 559
Add automatic SCRAM-SHA-256 password escaping and comprehensive documentation #797
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
base: main
Are you sure you want to change the base?
Conversation
…entation Co-authored-by: damacus <[email protected]>
…ng or encoding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ng or encoding Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
libraries/sql/role.rb
Outdated
end | ||
|
||
def escape_password_for_sql(password) | ||
return password if password.nil? || password.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Use nil_or_empty?
function for this check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use nil_or_empty?
function for the password check as suggested. The change replaces password.nil? || password.empty?
with the more concise nil_or_empty?(password)
. Commit: 9e7b3d4
Co-authored-by: bmhughes <[email protected]>
libraries/sql/role.rb
Outdated
# SCRAM-SHA-256 passwords contain $ characters that can be interpreted | ||
# by shell or string processing. Escape them to prevent mangling. | ||
if password.start_with?('SCRAM-SHA-256') | ||
password.gsub('\\', '\\\\\\\\').gsub("'", "''").gsub('$', '\\$') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Update this to escape backslash characters please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the backslash escaping from excessive \\\\\\\\
(8 backslashes) to proper \\\\
(4 backslashes) for correct SQL escaping. Commit: 6b2f5c7
documentation/scram-sha-256.md
Outdated
## Password Format | ||
|
||
SCRAM-SHA-256 passwords have this specific format: | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Specific the code block language as ruby to statisfy markdownlink MD040
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specified code block language as text
to satisfy markdownlint MD040. Commit: 623bf6e
documentation/scram-sha-256.md
Outdated
``` | ||
|
||
Example: | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Specific the code block language as ruby to statisfy markdownlink MD040
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specified code block language as text
to satisfy markdownlint MD040. Commit: 623bf6e
Changed from excessive \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ (8 backslashes) to proper \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ (4 backslashes) for SQL escaping. Each backslash in the original password is now correctly escaped as \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ (2 backslashes) in the result. Co-authored-by: bmhughes <[email protected]>
Co-authored-by: bmhughes <[email protected]>
Slowest examplesTop 10 slowest examples (0.01 seconds, 51.45% of total time)
|
Slowest examplesTop 10 slowest examples (0.01 seconds, 50.85% of total time)
|
This is ready to release. But I'm going to move it over to the new release workflow before releasing. |
Changes
This PR addresses the SCRAM-SHA-256 password handling issue where
$
characters in password hashes were being mangled during SQL execution, causing authentication failures.Key improvements:
SCRAM-SHA-256
$
characters are automatically escaped as\$
to prevent shell interpretation\\\\\\\\
to proper\\\\
for SQL safetynil_or_empty?
utility function for cleaner password validationSolution
Users can now simply write:
The cookbook automatically escapes the password for safe SQL execution.
Testing
Verified that:
$
and\
characters)Fixes #703.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.