Opened 5 weeks ago
Closed 5 weeks ago
#63303 closed defect (bug) (duplicate)
Direct access to wp-settings.php results in a fatal error due to undefined ABSPATH constant.
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | critical | Version: | |
Component: | Bootstrap/Load | Keywords: | close |
Focuses: | Cc: |
Description (last modified by )
When attempting to directly access wp-settings.php
via a browser (e.g., navigating to https://example.com/wp-settings.php
), a fatal error is triggered:
[16-Apr-2025 19:58:43 UTC] PHP Fatal error: Uncaught Error: Undefined constant "ABSPATH" in /.../wp-settings.php:34 Stack trace: #0 {main} thrown in /.../wp-settings.php on line 34
This occurs because ABSPATH
is not defined unless wp-settings.php
is loaded through wp-config.php
.
Suggested Solution:
To avoid direct access and prevent such fatal errors, I recommend adding a conditional check at the top of the wp-settings.php
file like this:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Attachments (2)
Change History (15)
#3
@
5 weeks ago
I don't get a fatal. Depending on the permalink settings I get a 404 or 301. How can I reproduce the issue?
#4
follow-up:
↓ 5
@
5 weeks ago
@Presskopp, when you directly open the URL http://localhost:8889/wp-settings.php
#5
in reply to:
↑ 4
;
follow-up:
↓ 6
@
5 weeks ago
Replying to dilipbheda:
@Presskopp, when you directly open the URL http://localhost:8889/wp-settings.php
You're right, I had a typo in my url, I'm sorry.
#7
@
5 weeks ago
- Keywords dev-feedback has-testing-info added
Combined Bug Reproduction and Patch Test Report
Description
This report validates that the patch works as expected.
Patch tested: https://core.trac.wordpress.org/attachment/ticket/63303/63303.patch
Environment
- WordPress: 6.9-alpha-60093-src
- PHP: 8.4.6
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.4.6)
- Browser: Chrome 135.0.0.0
- OS: Windows 10/11
- Theme: Twenty Twenty-Five 1.2
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.0
Bug Reproduction
- Open <sites_url>/wp-settings.php
- 🐞Bug occurs
Expected Results
- No errors, white page.
Actual Results
- ✅ Issue resolved with patch.
Additional Notes
Technically, all the root files include wp-load.php
except for this one. And this has been historically. I wonder when this started happening, or if this has been for so long.
I'm not sure if this file has to be directly accessed like wp-cron.php
or the liking. Since obviously wp-load.php
is not required by this file I would rather suggest using classic a die alternative, instead of loading wp-load.php
Supplemental Artifacts
Attach better alternative 63303.2.patch
as suggested by OP
#9
in reply to:
↑ 8
@
5 weeks ago
Replying to sabernhardt:
Bruh, haven't you checked my last post?👎
#10
follow-up:
↓ 11
@
5 weeks ago
I just edited the formatting and filepath in the description and removed the version (because I could reproduce the error with WordPress 5.6, this is not new to 6.8).
#11
in reply to:
↑ 10
@
5 weeks ago
Replying to sabernhardt:
I just edited the formatting and filepath in the description and removed the version (because I could reproduce the error with WordPress 5.6, this is not new to 6.8).
Ok, I saw a convoluted text with all the diff changes in my email digest, so I confused the message.
Btw, in the last couple of reports I've been observing that you only are posting suggestions, you can't attach reports to Milestones?
#12
follow-up:
↓ 13
@
5 weeks ago
I do not commit code changes, so ultimately any time I edit the milestone it is no more than a recommendation.
Back to the topic of this ticket, I do not have an opinion about exit
/die()
or wp_load.php
. Also, other files might need to block direct access just as much as wp-settings.php
(it is one of the files included on #62722).
#13
in reply to:
↑ 12
@
5 weeks ago
- Keywords close added; has-patch dev-feedback has-testing-info removed
- Resolution set to duplicate
- Status changed from new to closed
Replying to sabernhardt:
Back to the topic of this ticket, I do not have an opinion about
exit
/die()
orwp_load.php
. Also, other files might need to block direct access just as much aswp-settings.php
(it is one of the files included on #62722).
Great catch.
I advocate for triaging harder.
I do not commit code changes, so ultimately any time I edit the milestone it is no more than a recommendation.
Even a good milestone recommendation will bring attention and prob get more useful commits into cycles. Zillions of good patches are being lost in the space.
For example, if you can propose 6.8.2 to #62722, would be great.
I believe we can resolve this by including the following code to load the WordPress bootstrap files:
I've noticed similar usage in other core files like
wp-comments-post.php
wp-cron.php
wp-login.php