Presigned URL redirects write a unique never read entry to core/htmlpurifier on every file request

Open
#775 0 comments 0 reactions 0 assignees View on GitHub

@Alex-Accipio is already working on this.

Since Nov 3, 2026.

  • #10 by @uaiblaine — merged
  • #776 by @Alex-Accipio — open

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
aws, php

Research direction

Start in object_file_system::redirect_to_presigned_url() in classes/local/store/object_file_system.php, where the signed URL is passed to core redirect(). Check how core redirect() and clean_text() handle the URL, which is what writes the core/htmlpurifier cache entry. Reproduce by counting entries under cachestore_file core_htmlpurifier before and after several requests to a presigned fixture. Done when the redirect no longer writes to that cache and the presigned-URL tests still pass.

Written by the indexing model from the issue text.

Description

object_file_system::redirect_to_presigned_url() sends the signed URL through core redirect(). Core redirect() sanitises the target with clean_text(), and purify_html() caches the result in core/htmlpurifier keyed on the full input text with no TTL.

A presigned S3 url changes every second (X-Amz-Date, X-Amz-Signature) so every file request:

  • writes a new ~1.5KB entry to core/htmlpurifier that is never read again
  • constructs an HTMLPurifier instance to sanitise a URL the AWS SDK generated

To reproduce:

  1. Configure S3 with presigned URLs enabled, whitelist *, minimum size 0.
  2. Open /admin/tool/objectfs/presignedurl_tests.php once so the fixtures files are pushed to the bucket
  3. Count entries in the core/htmlpurifier store. With the default file store:
    find <moodledata>/cache/cachestore_file/default_application/core_htmlpurifier -type f | wc -l
  4. Request one fixture several times, one second apart, bypassing the browser cache:
for i in $(seq 1 10); do
  curl -sk -o /dev/null -w '%{http_code}\n' -b "MoodleSession=<cookie>" \
    "https://<site>/pluginfile.php/1/tool_objectfs/settings/0/testimage.png?forcedownload=1"
  sleep 1
done
  1. Count again

Moodle could add a TTL for htmlpurifier but the TTL doesn't remove the unnecessary write. The URL is generated by the AWS SDK, not from user input, I'm not sure there is value in needing to run htmlpurify on this, so I think there should be a change in objectfs to send the redirect directly.

Dominant language
PHP
Stars
102
Forks
85
Avg merge
4d 21h
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from catalyst/moodle-tool_objectfs

All issues in catalyst/moodle-tool_objectfs

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.