Problem/Motivation

Entering a valid relative path starting with leading / in Akamai Cache Control form is throwing below exception:

InvalidArgumentException: The URL //node/1 is not managed by Akamai. Try setting your Akamai base url. in Drupal\akamai\AkamaiClientBase->purgeUrls() (line 252 of modules/contrib/akamai/src/AkamaiClientBase.php).

On debugging, I found that the submitForm function in CacheControlForm.php is appending a / at the start of each path($urls_to_clear[] = trim('/' . $path);) before calling $this->akamaiClient->purgeUrls($urls_to_clear). Hence every relative input path with a leading /, Ends up having two leading // and the same gets passed to purgeUrls() which in turn is throwing exception.

Steps to reproduce

  • Login as an admin on the site.
  • Configure the akamai module at /admin/config/akamai/config and make sure you enter a valid Base Path.
  • Go to the path /admin/config/akamai/cache-clear
  • In the "Paths/URLs/CPCodes" form element, Enter a valid node's relative path(Example: /node/1).
  • In the "Purge Method" form element, Ensure "Url" radio is selected.
  • Click on "Start Refreshing Content" submit button.
  • You should get the HTTP 500 error.

Proposed resolution

  • In the validateForm() function, Set error if any of the relative path is starting with a leading /

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Comments

kunalkursija created an issue. See original summary.

kunalkursija’s picture

Issue summary: View changes
kunalkursija’s picture

Issue summary: View changes
kunalkursija’s picture

Issue summary: View changes
kunalkursija’s picture

Assigned: kunalkursija » Unassigned
Status: Active » Needs review
StatusFileSize
new1.1 KB

Adding a patch. The code is adding the validation to set form error in the case of relative paths starting with a leading /.

kunalkursija’s picture

Title: InvalidArgumentException: The URL //node/1 is not managed by Akamai. » InvalidArgumentException: The URL //node/1 is not managed by Akamai
kunalkursija’s picture

The previous patch had an issue with the variable name. This new patch rectifies that.

WidgetsBurritos’s picture

Version: 8.x-3.0-alpha8 » 4.x-dev
Status: Needs review » Closed (outdated)

This is no longer relevant as as of #3244366: Remove URL validation when invalidating cache. This is presently in the 4.x-dev branch, but will get pushed out as part of a larger release in the next day or so.