Action set-finished.json would eventually have an invalid token value.
The issue might be related to caching of some sort as the result of getGenericH5PIntegrationSettings does not seem to be updated for each request, but would only be re-run when caches are cleared. The result is that security token becomes outdated after a certain number of hours.
In case of embed the solution seems to be to force no caching (please note the options part of the route):
h5p.content.embed:
path: '/h5p/{id}/embed'
defaults:
_controller: '\Drupal\h5p\Controller\H5PEmbed::embed'
_title: 'H5P Embed'
requirements:
_permission: 'access content'
id: \d+
options:
no_cache: TRUE
The solutions for other pages/widgets/formatters using H5PIntegration might probably differ. The best approach would be to just disable the caching for those parameters being passed to the drupalSettings.
The code seems to be using cache busting logic for embed page and field formatter, though that does not seems to be enough:
$response = [
'#cache' => [
'tags' => [
'h5p_content:' . $id,
],
],
];
The issue is that the drupalSettings will only be invalidated along with the entity itself, yet the token has nothing to do with the entity. Setting the value to be invalidated after certain time would only work if the time value for cached token creation time is available. The best simplest solution might be to set the max-age to be equal to 0 and prevent caching altogether.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3036486-disable-cached-user-6.patch | 597 bytes | amourow |
Issue fork h5p-3036486
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pjotr.savitski commentedComment #3
Raman Starshykh commentedComment #4
linichalexey commentedComment #5
amourowChange the cache attribute to
'max-age' => 0fixed the problemThe user data in
drupalSettings.h5p.H5PIntegration.userwas cached and caused the token validation error.Comment #6
amourowReroll patch for latest dev
Comment #7
pjotr.savitski commentedSubmitted patch should fix the issue, but it will also fully disable caching as such and that might cause some performance issues.
Maybe max age could be set to the duration of that token. It seemed to be around one day, if I remember that correctly.
I am also not sure of removing cache tags is a good idea. The cache should be reset along with any changes to that content entity, with maximum cache age less than the token lifetime. I'd even say it might be a good idea to leave at least one hour (maybe even more) for the page to function properly without doing a refresh. The last aspect will surely be useful in case of large columns and presentations.
Comment #8
illeace commentedIf I'm reading the H5P core library's validToken() function (vendor/h5p/h5p-core/h5p.classes.php line 3351) correctly, whenever a token is generated, it is going to be valid for at least 12 hours and up to 24 hours. Rather than disabling caching completely, what if the max-age was set to 12 hours?
Comment #9
illeace commentedComment #11
illeace commentedOK, as @pjotr.savitski suggests, I've created an issue fork that sets the max age to align with the token expiration time. This ensures that the Drupal cache never serves an H5P with an already-expired token. This is ready to be tested, but a bit time-consuming since it involves waiting for 12 hours for the cache to expire.
Comment #12
illeace commentedThe help simplify testing a bit, here's the test I've been using:
{"success":true}{"success":true}Comment #13
maya maierTested, new token expiry works as expected. Marking RTBC.
Comment #16
sim_1Merged and marking as fixed.