-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Site Health false positive: WP_DEBUG_LOG warning when debug.log is outside wp-content - Ticket #64071 #10684
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: trunk
Are you sure you want to change the base?
Changes from 2 commits
f99e009
bcebdf8
3749fef
8636002
ffda9d8
b98ece6
2da8e22
97e37bd
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1409,18 +1409,37 @@ public function get_test_is_in_debug_mode() { | |||||
|
|
||||||
| if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { | ||||||
| if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { | ||||||
| $result['label'] = __( 'Your site is set to log errors to a potentially public file' ); | ||||||
| $debug_log_path = WP_DEBUG_LOG === true ? WP_CONTENT_DIR . '/debug.log' : WP_DEBUG_LOG; | ||||||
| $debug_log_path = realpath( $debug_log_path ); | ||||||
|
||||||
| $debug_log_path = realpath( $debug_log_path ); | |
| $debug_log_path = realpath( dirname( $debug_log_path ) ) . DIRECTORY_SEPARATOR; |
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.
Yes, that could be done. Then I do not think so to check this ini_get( 'error_log' ) === WP_CONTENT_DIR, just check for directory what it is in and show the details. As because, we are always checking with WP_CONTENT_DIR in debug.log
I will update the PR with the requested change.
Outdated
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.
This should help ensure that there isn't a false positive of there being another sibling directory name with the same common prefix.
| $absolute_path = realpath( ABSPATH ); | |
| $absolute_path = realpath( ABSPATH ) . DIRECTORY_SEPARATOR; |
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, Thanks.
Outdated
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.
| __( 'The value, %s, has been added to this website’s configuration file. This means any errors on the site will be written to a file which is potentially available to all users.' ), | |
| __( 'The constant, %s, has been added to this website’s configuration file. This means any errors on the site will be written to a file which is likely publicly accessible.' ), |
Outdated
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.
| $result['label'] = __( 'Your site is set to log errors to a file outside the public directory' ); | |
| $result['label'] = __( 'Your site is set to log errors to a file outside the document root' ); |
Outdated
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.
| __( 'The value, %s, has been configured to write errors to a file outside the WordPress directory. This is a good practice as the log file is not publicly accessible.' ), | |
| __( 'The configuration constant, %s, has been set to write errors to a file outside the WordPress directory. This is a good practice as the log file should not be publicly accessible.' ), |
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.
Should this be changed?
Uh oh!
There was an error while loading. Please reload this page.
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.
Amm, I thought so as well, but I have kept it as is. This is because the current condition will only provide us if
WP_DEBUG_LOGis set or not, and that is enough here for a check. Ultimately we are usingini_get( 'error_log' )to get the error_log config.IMO, there is no harm to change this, and also there is no harm to keep as is, as ultimately the output that we need would be same.
Also if we need to consider a performance check, IMO reading from constant would be faster, then calling a function for the same and then toggling the condition via
! empty.So for first thing,
defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOGa simple constant hashlookup, while for this,! empty( ini_get( 'error_log' ) ), a function call to check for value, then check for empty and then toggle condition. Still it's very negligible difference.I am okay to accomodate the above change, but there is no requirement in it unless you see something specific?
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.
The performance here doesn't matter since it's only when the Site Health tests runs, right? It's not running with request.
My concern is if a server is misconfigured to have an
error_logwet to somewhere in the document root (ABSPATH), even ifWP_DEBUG_LOGisn't being set.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.
Yes it won't have much impact related to performance, but thought to raise. We can neglect this.
If I am understanding correctly, you are saying anyhow someone have set this debug file to use document root, that is, from somewhere they call this,
ini_set( 'error_log', 'path-to-document-without-wp-debug-log-constant' )without explicitly setting the constant value, So in this case, our condition would failif ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {, and it would show the false information.But that could ever happen? Because let's say
WP_DEBUG_LOGis not set and somehow the error_log with document root path is configured, then we are never outputing user thatyou have enabled debug_log as good practice, instead we would say the default message,Your site is not set to output debug information, though this is misleading as error_log is configured and we need to provide information that it is good practice or not based on the path.Also, if we use
! empty( ini_get( 'error_log' ) )it as a condition, the point would again be misleading because we would show whatever message need to show based on path, but we are saying to user that, 'The constant,WP_DEBUG_LOG.....' is set but that is not set as per the edge case we are assuming.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.
Consider this case: someone may not define
WP_DEBUG_LOGat all, but theirwp-config.phpmay have this:This would not be detected as a problem currently in Site Health test, but it would be a similar problem, as if there are any
error_log()calls being made, they'll go to that public file. The same issue would happen if the php.ini was set with anerror_logset to a public location, right?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.
Thanks @westonruter, Yes agreeing to the point, Concerning part here is below message to me,
It say's 'The constant,
WP_DEBUG_LOG, has been added to this website’s configuration file', but as per the example shared, theWP_DEBUG_LOGis not actually being set, the error log is added by this statement,ini_set( 'error_log', __DIR__ . '/error-log.txt' );, So we need to change the statement here to more generic.Ideally if I am a user and see's this message, I will first check this constant,
WP_DEBUG_LOG, and I would not able to find how this is set (but actually that is not set as per example), hence I would not get an idea that it was set from server or somewhere else.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.
Agreed. We could have a separate message when the
WP_DEBUG_LOGconstant is set, and then another general one about theerror_logbeing misconfigured.