Drupal can be "consumed" from other context than classic browsers. This can be drush request or cURL request for which there will likely be no "Referer" header in the HTTP request, but it can also happen to be from applications which set non standard URI in the Referer field.
For example, Adobe AIR applications sets a Referer header with the following pattern : air:/[filename].swf and Drupal duly store this URI in the "referer" field of dblog entries.
The issue is that when trying to render such dblog entries (at admin/reports/dblog/event/[id]), it tries to treat theses URI as routable URL and render theses as links, which fails :
InvalidArgumentException: The URI 'app:/[filename].swf' is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal. in Drupal\Core\Utility\UnroutedUrlAssembler->assemble() (line 64 of /project/www/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php).
Whether it's good or bad to but put such bizarre URI in the Referer header of such request is out of scope for this issue as Drupal should always be able to render any of its dblog entries. Moreover, having this piece of information in dblog entries is very valuable to understand that the request comes from such an application.
I think that Drupal should keep on storing this kind of non-standard URI in dblog entries and output them as plain text and not as a link.
This issue is very close to #2755497: InvalidArgumentException in dblog entries due to invalid location which try to solve a similar issue for the "Location" field.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | exception_thrown_when-2858182-14.patch | 1.31 KB | cilefen |
| #9 | exception_thrown_when-2858182-9.patch | 706 bytes | garphy |
Comments
Comment #2
dagmarWell if the text is a valid URL we can display it as a link. UrlHelper::isValid can help with that.
Comment #3
dagmarTentativelly marking this as Novice.
Plan:
DbLogController::eventDetails()Check if the url is valid before render it as a link.DbLogTestto create a log entry with arefererlike mentioned in the issue summary. You can use DbLogTest::testLogEventPage() as base.Comment #4
cilefen commentedThis is major priority according to the guidelines. I related an issue where a "bad" URI can appear from an external source.
Comment #5
garphyComment #6
garphyI think that the issue root is actually from an incorrect behavior of UrlHelper :
*
UrlHelper::isValid('air:/test.swf') === TRUE*
UrlHelper::isExternal('air:/test.swf') === FALSESo we can't really rely on
UrlHelper::isValid()here becauseUrlHelper::isExternal()result will leadUnroutedUrlAssember::assemble()to fail.Either
air:/test.swfis an invalid URI, or it has to be considered as an external URL.IMHO,
UrlHelper::isExternal('air:/test.swf')should beTRUE. Thoughts ?Comment #7
cilefen commentedIf there is ambiguity, I remove the Novice tag until there is concensus. A test proving the issue would be a good start.
Comment #8
dagmarThanks @garphy.
UrlHelper::isExternalseems appropriated.Comment #9
garphyHere's an update of UrlHelperTest which exhibits that air:/filename.swf is not considered an external URL.
Testbot should fail.
Comment #10
garphyComment #12
dagmarMaybe someone else can help with this issue. Unassigned for now.
Comment #13
cilefen commentedThis can be fixed by copying default.services.yml to services.yml and adding 'air' to parameters.filter_protocols. That is not a solution to invalid referrer lines throwing an exception, of course.
Comment #14
garphyMaybe we can "detect" that the provided referer don't match any of the protocols listed in services.yml and render it as plain text instead of a link ?
Comment #15
cilefen commentedThis demonstrates that in Drupal 8, you can create a Url that cannot be generated.
Comment #16
cilefen commentedThe test in #9 illustrates the issue to a degree, but because of #13, it is not a representative test. I suggest this improvement: causing or creating a dblog event with a "bad" referer then trying a page load.
Comment #17
dagmarI just created this: #2868725: Refactor how dblog module is rendering links in event details
Comment #18
dagmarI'm marking this as a duplicate of #2868725: Refactor how dblog module is rendering links in event details. We should work in a generic solution for several issues we have related the way dblog render links.