Bogus URL tries to use ErrorPresenter from bogus module which does not exist and results in 500 instead of 404

2 years ago

josef.sabl
Backer | 146
+
0
-

Hi, I have problem with default routing and addresses like:

http://myweb.cz/humans.txt

These requests are generated by crawlers as they look for humans.txt file in the root (but this is only an example, other patterns appear as well, e.g. help.txt).

And the default router tries to route it to:

module: humans
presenter: txt
action: default

There is nothing like that and it wants to load ErrorPresenter from module Humans, which obviously does not exist. And it results in 500 Server Error. Correct reply would be 404 Not Found.

What to do about it?

UPDATE: Clarified question a bit.

Last edited by josef.sabl (2017-02-16 13:36)

2 years ago

Pavel Kravčík
Member | 944
+
0
-

Default router (2.3, 2.4) show humans.txt if you put this file in root (www) correctly.

2 years ago

josef.sabl
Backer | 146
+
-1
-

Pavel Kravčík wrote:

Default router (2.3, 2.4) show humans.txt if you put this file in root (www) correctly.

So should I add all combinations of [a-z0–9]+\.[a-z0–9]{1,10} as files to my root? I don't think so ;-) humans.txt is of course only an example, robots can try anything.

2 years ago

CZechBoY
Member | 3211
+
0
-

I don't get what do want to achieve. Do you want load presenter HumansPresenter and fire action actionTxt or?

2 years ago

Pavel Kravčík
Member | 944
+
0
-

I guess I get it now. He doesnt want exception.

It's simple rewrite run() func in ErrorPresenter `with `$e->getCode();

2 years ago

josef.sabl
Backer | 146
+
0
-

CZechBoY wrote:

I don't get what do want to achieve. Do you want load presenter HumansPresenter and fire action actionTxt or?

I want to return 404, not 500. Also I clarified the question a bit, I thought it was obvious, my bad…

Last edited by josef.sabl (2017-02-16 13:36)

2 years ago

josef.sabl
Backer | 146
+
0
-

Pavel Kravčík wrote:

I guess I get it now. He doesnt want exception.

It's simple rewrite run() func in ErrorPresenter `with `$e->getCode();

Unfortunately no. I would not need to do anything in ErrorPresenter. The error presenter would correctly return 404 code in the absence of, say, template. The problem here is, that default router tries ErrorPresenter from module Humans, which does not exist.