Public accessibility of cron.php causes errors and security concerns
Preconditions and environment
Magento / Adobe Commerce 2.4.8
Steps to reproduce
- Install Magento 2
- Open a browser and navigate to https://yourdomain.com/cron.php.
Expected result
- cron.php should not be publicly accessible in a production environment.
- Magento cron jobs should only run via CLI (bin/magento cron:run) and system cron tasks.
Actual result
- cron.php is exposed to the web by default.
- If executed via HTTP, it can cause runtime errors, e.g.:
TypeError: implode(): Argument #1 ($array) must be of type array, string given in /app/bvu7cj4frt2um/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:967
Additional information
- cron.php exposure appears to be a legacy carryover from Magento 1, where web crons were common on shared hosting.
- Current Adobe Commerce documentation recommends system-level CLI cron only (bin/magento cron:run).
- Executing cron.php via HTTP can cause errors (e.g. implode(): Argument #1 ($array) must be of type array, string given) and may unnecessarily increase the attack surface.
- In modern deployments, cron.php is not required, but its presence in pub/ causes confusion about best practices.
- Clarification is needed whether this file should be considered deprecated or officially supported.
Release note
No response
Triage and priority
- [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- [x] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Hi @Gurdit. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.
- For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this - To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
- [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
- [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
- [ ] 3. Add
Area: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced on 2.4.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! - [ ] 5. Add label
Issue: Confirmedonce verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
You should have an entry in .htaccess (within pub folder) that prevents cron.php execution, like this:
https://github.com/magento/magento2/blob/c8ff03033f9d79d9e6b6482086940153a28c6443/pub/.htaccess#L225-L234
@Gurdit, If you are running on NGINX, convert the .htaccess rules into the corresponding NGINX configuration.
@devchris79 @WebHostingAce Thanks for your Contribution!!
Hi @Gurdit,
Thanks for your reporting and collaboration.
Could you please refer the above comments https://github.com/magento/magento2/issues/40190#issuecomment-3285755135 https://github.com/magento/magento2/issues/40190#issuecomment-3290172608 and please let us know if you are still facing any issue.
Thanks.
Possible Strategies / Fixes
You’ll have to choose a path depending on your constraints (hosting, infra, CDNs, etc.). Below are options; I’ll also sketch a sample patch.
| Strategy | Pros | Cons / Risks |
|---|---|---|
| Block HTTP access via web server (Apache / Nginx rules) | Simple, doesn’t require code change. Can return 403/404 for cron.php via HTTP. | Requires control of server config. Might block legitimate HTTP calls if any custom use. |
| In-code guard in cron.php itself | Self-protecting: if accessed via HTTP, exit early or redirect. | cron.php may be overwritten in upgrades; you must maintain patch. |
| Remove/disable cron.php file in pub/ (or root) via installation process | Eliminates the endpoint entirely. | Some legacy plugins might expect it; may break fallback, legacy workflows. |
| Wrap cron-logic so HTTP execution fails safely | Even if cron.php is invoked, it doesn’t crash (fails silently or safe exit). | Adds overhead and complexity; must ensure no side effects. |
| Documentation / deprecation / backward-compatibility announcement | Sets expectations for users; upstream can follow with official removal. | Doesn’t solve in existing deployed sites; reactive. |
Sketching a Patch / Guard Logic
If you go with the in-code guard approach, place early checks in pub/cron.php before executing the core cron logic:
Additionally, wrap around parts where arrays or implode is used, to avoid runtime errors when input is malformed:
The key is: short-circuit HTTP requests.
Alternative Server-Level Blocks
Apache (.htaccess inside pub/)
Nginx
Steps You’d Take (Practical)
-
Identify exactly where
cron.phpresides in your Magento setup (root/cron.phporpub/cron.php). -
Decide whether your environment allows server config changes.
-
If yes → block at Apache/Nginx level (preferred, cleaner).
-
If no → patch
cron.phpwith in-code guard.
-
-
If patching, keep it in a diff file or patch folder so it’s version-controlled.
-
Add unit / integration tests (if possible) for HTTP vs CLI invocation.
-
Deploy to staging first, then verify:
-
curl https://yourdomain.com/cron.phpgives404/403or no execution. -
Cron tasks via CLI (
bin/magento cron:run) still run as expected. -
No side effects in other flows.
-
-
For completeness, consider filing a pull request (if your change is generic) or join discussion upstream to deprecate/remove the public
cron.php.
@koushikch7 Thanks for your Contribution!!.
Hi @Gurdit,
Kindly refer the above comment and please let us know if you are still facing any issue.
Thanks.
Would be good to know if anybody still relies on the pub/cron.php file to exist, because in my opinion nobody should rely on it and we should simply remove it from the codebase.
Hello @Gurdit,
Thanks for the report and collaboration!
We have tried to reproduce the issue in the latest development branch i.e. 2.4-develop but the issue is not reproducible for us in both Apache and Nginx.
Both gives us 404 page not found error as below:
Please try to reproduce the issue in the 2.4-develop branch and let us know if we missed anything.
Thank you
Hello @Gurdit,
Gentle reminder for this issue.
Thank you
Would be good to know if anybody still relies on the
pub/cron.phpfile to exist, because in my opinion nobody should rely on it and we should simply remove it from the codebase.
I agree with @hostep's comment above, I think it is not recommended to use the web version of cron.php, hence confirming this issue.
Hello @Gurdit,
Thank you for bringing this issue to our attention. If you have a potential solution, we encourage you to submit a pull request. Your contributions significantly enhance Magento Open Source for everyone. Should you need any assistance, please don't hesitate to ask!
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-16194 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.