-
Notifications
You must be signed in to change notification settings - Fork 73
Skip server certificate verification for MariaDB connections #334
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1988,6 +1988,17 @@ private static function run( $cmd, $assoc_args = [], $send_to_shell = true, $int | |
| unset( $assoc_args['dbpass'], $assoc_args['password'] ); | ||
| } | ||
|
|
||
| // MariaDB 11.4 enables TLS server certificate verification by default. WP-CLI | ||
| // connects the same way WordPress does, which does not verify the certificate, | ||
| // and against MariaDB's auto-generated self-signed certificate verification | ||
| // either just warns on STDERR that it disabled itself or fails outright. Opt out | ||
| // explicitly to keep the previous behaviour, unless the user asked to verify. | ||
| if ( 'mariadb' === Utils\get_db_type() | ||
| && ! isset( $assoc_args['ssl-verify-server-cert'] ) | ||
| && ! isset( $assoc_args['skip-ssl-verify-server-cert'] ) ) { | ||
| $required['skip-ssl-verify-server-cert'] = true; | ||
| } | ||
|
Comment on lines
+1991
to
+2000
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: sed -n '1960,2025p;835,860p;2360,2400p' src/DB_Command.phpRepository: wp-cli/db-command Length of output: 4415 🏁 Script executed: python3 - <<'PY'
from pathlib import Path
p = Path('src/DB_Command.php')
text = p.read_text()
for start,end in [(1960,2025),(835,860),(2360,2400)]:
print(f'--- {start}-{end} ---')
for i,line in enumerate(text.splitlines(),1):
if start <= i <= end:
print(f'{i}:{line}')
PYRepository: wp-cli/db-command Length of output: 5106 🏁 Script executed: rg -n "ssl-verify-server-cert|skip-ssl-verify-server-cert|get_current_sql_modes|get_posts_table_charset|function run\(" src/DB_Command.phpRepository: wp-cli/db-command Length of output: 859 🌐 Web query:
💡 Result: The components you identified are part of the wp-cli/db-command package, which manages database interactions for WP-CLI [1][2][3]. get_current_sql_modes This is a internal function used by WP-CLI to retrieve the active SQL modes of the MySQL/MariaDB session (via Citations:
🏁 Script executed: sed -n '900,1040p;1180,1260p;2200,2265p' src/DB_Command.phpRepository: wp-cli/db-command Length of output: 8498 🏁 Script executed: rg -n "function get_defaults_flag_string|get_defaults_flag_string\(" src/DB_Command.phpRepository: wp-cli/db-command Length of output: 828 🏁 Script executed: sed -n '520,700p;1040,1185p;2200,2265p' src/DB_Command.phpRepository: wp-cli/db-command Length of output: 13003 🏁 Script executed: python3 - <<'PY'
from pathlib import Path
text = Path('src/DB_Command.php').read_text().splitlines()
for start,end in [(520,700),(1040,1185),(2200,2265)]:
print(f'--- {start}-{end} ---')
for i,line in enumerate(text,1):
if start <= i <= end:
print(f'{i}:{line}')
PYRepository: wp-cli/db-command Length of output: 14839 🏁 Script executed: rg -n "function get_defaults_flag_string|get_defaults_flag_string\(" src/DB_Command.php && sed -n '1260,1385p' src/DB_Command.phpRepository: wp-cli/db-command Length of output: 3946 🏁 Script executed: sed -n '2280,2335p' src/DB_Command.phpRepository: wp-cli/db-command Length of output: 1842 🏁 Script executed: python3 - <<'PY'
from pathlib import Path
text = Path('src/DB_Command.php').read_text().splitlines()
for start,end in [(2280,2335)]:
print(f'--- {start}-{end} ---')
for i,line in enumerate(text,1):
if start <= i <= end:
print(f'{i}:{line}')
PYRepository: wp-cli/db-command Length of output: 2140 Forward SSL flags into internal DB queries. 🤖 Prompt for AI Agents |
||
|
|
||
| $final_args = array_merge( $required, $assoc_args ); | ||
|
|
||
| // Filter out empty string values to avoid passing empty parameters to MySQL commands | ||
|
|
@@ -2232,6 +2243,7 @@ private static function get_mysql_args( $assoc_args ) { | |
| 'skip-pager', | ||
| 'skip-reconnect', | ||
| 'skip-ssl', | ||
| 'skip-ssl-verify-server-cert', | ||
| 'socket', | ||
| 'ssl', | ||
| 'ssl-ca', | ||
|
|
@@ -2243,6 +2255,7 @@ private static function get_mysql_args( $assoc_args ) { | |
| 'ssl-fips-mode', | ||
| 'ssl-key', | ||
| 'ssl-mode', | ||
| 'ssl-verify-server-cert', | ||
| 'syslog', | ||
| 'table', | ||
| 'tee', | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: wp-cli/db-command
Length of output: 8621
🏁 Script executed:
Repository: wp-cli/db-command
Length of output: 38664
🌐 Web query:
WP-CLI DB_Command skip-ssl-verify-server-cert query assoc_args self::run get_mysql_args debug STDERR💡 Result:
In WP-CLI's
DB_Commandimplementation, thessl-verify-server-certflag and its associated handling are primarily used to manage SSL/TLS connection requirements and suppress specific warnings during database operations, particularly when using MariaDB [1][2]. Key details regarding the components you mentioned: 1.ssl-verify-server-cert: This flag is included in WP-CLI's internal allow-list for MySQL/MariaDB connection arguments [1][3]. When using MariaDB, WP-CLI may automatically inject--ssl-verify-server-certinto the database command to prevent "insecure passwordless login" warnings from clutteringSTDERRduring automated processes like Behat tests [1][2]. 2.get_mysql_args(): This method inDB_Commandis responsible for filtering user-provided arguments against an allow-list of valid MySQL client options [4]. It ensures that flags likessl-verify-server-cert,ssl, andskip-sslare correctly passed to the underlying MySQL or MariaDB client binary [4]. 3.self::run()anddebug: WP-CLI executes database commands by constructing a shell command and invoking it viaself::run()[5][6]. When the--debugglobal flag is used, WP-CLI outputs the final, constructed MySQL command string and the associative arguments being passed, which is useful for verifying that flags like--ssl-verify-server-certare being correctly applied [7][6][4]. 4.STDERR: In many environments, especially with MariaDB, SSL warnings are output toSTDERR[1][2]. If these warnings occur during SQL mode discovery or connection establishment, they can sometimes cause WP-CLI commands to fail or produce unexpected output [7][2]. Technical Context and Known Issues: The handling of SSL and default configurations has been a point of development within WP-CLI [8][3]. Specifically, WP-CLI often uses a--no-defaultsflag by default to avoid issues with misconfigured local environments, but this can prevent the MySQL client from respecting SSL configuration files [9][10][2]. Users encountering SSL connection failures (e.g., certificate verification errors) often need to use the--defaultsflag or explicitly pass additional SSL-related arguments [9][3][10]. Recent PRs have focused on improving howwp dbcommands handle these arguments to ensure better compatibility with modern SSL/TLS-secured database environments [3][4].Citations:
wp db query --defaultshandling #285🏁 Script executed:
Repository: wp-cli/db-command
Length of output: 5999
Assert the spawned mysql argv
features/db-query.feature:16-19—--debugcan print the parsed assoc args beforeself::run(), so this check can pass without proving the option reached the MySQL client. Assert the final client arguments instead.🤖 Prompt for AI Agents