One unescaped class name: Contributor stored XSS in Gallery PhotoBlocks
A gallery setting cleaned with sanitize_text_field() kept its double quotes and landed raw inside an HTML attribute, letting a Contributor plant JavaScript that runs in an administrator’s browser.
Context: Incomplete fix of CVE-2026-66448
- Advisory
- CVE-2026-107323
- CVE
- CVE-2026-107323
- Affected
- Gallery PhotoBlocks (WordPress plugin) < 1.3.6, patched in 1.3.6
- Weakness
- CWE-79 (Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'))
- Reading
- ~6 min · 14 Oct 2026
Cross-site scripting in WordPress plugins is common enough that it is easy to stop reading the advisories. This one is not the usual “someone forgot to escape anything”. The plugin did clean the value on the way in, and its developers had just shipped a security update that escaped the neighbouring attributes in the same template. One field was missed, and the cleaning function it went through was the wrong one for where the value ended up.
The lesson is about output context: the same string is harmless in one place in an HTML page and dangerous in another, and the escaping has to match the place.
A little theory: escaping depends on where the value lands
An HTML document has several parsing contexts, and each one has its own special characters:
| Context | Example | What breaks out | WordPress escaper |
|---|---|---|---|
| Element body | <p>VALUE</p> |
< starts a new tag |
esc_html() |
| Quoted attribute | <img class="VALUE"> |
" ends the attribute |
esc_attr() |
| URL attribute | <a href="VALUE"> |
javascript: schemes, " |
esc_url() |
| Script block | <script>var x = VALUE</script> |
</script>, quotes |
wp_json_encode() / esc_js() |
The row that matters for this post is the attribute one. Inside class="...", an attacker does not need a single angle bracket. A double quote closes the attribute, and everything after it is parsed as new attributes on the same element, including event handlers such as onload or onerror. A filter that strips tags but keeps quotes does nothing here.
That is what sanitize_text_field() does. It is an input sanitiser: it strips tags, removes line breaks and extra whitespace, and is meant for storing plain text. It does not encode ". So x" onload="alert(1) passes through it unchanged.
The three WordPress output functions you will meet most often:
esc_attr()encodes&,<,>,"and'as entities. It is the right tool for any value placed inside a quoted attribute.esc_html()does the same encoding and is meant for text in the element body. It also neutralises quotes, but use the function that names the context, so a reviewer can check it at a glance.wp_kses()/wp_kses_post()are for values that are supposed to contain some HTML: they keep an allow-list of tags and attributes and drop the rest. They are the wrong choice for an attribute value, which should never contain markup at all.
The rule that follows: sanitise on input to keep the data well-formed, and escape on output, for the exact context, every time you echo.
The finding
Gallery PhotoBlocks (plugin slug photoblocks-grid-gallery) builds image-grid galleries that are embedded with a shortcode. Galleries are edited in wp-admin, and saving one goes through an AJAX handler (wp_ajax_pb_save_gallery) that is open to any user with the edit_posts capability, meaning Contributor and above.
Each gallery has a settings object. One of those settings, image_class, lets the editor add extra CSS classes to every image. Here is its whole path through the code, from the 1.3.4 source.
Saving, in admin/class-photoblocks-admin.php:
public function save_gallery() {
// ...
if ( ! current_user_can( 'edit_posts' ) ) { exit( 0 ); } // Contributor+
if ( check_admin_referer( 'photoblocks', 'photoblocks' ) ) {
// ...
$data = array_map( 'sanitize_text_field', json_decode( wp_unslash( $_POST['settings'] ), true ) );
// custom_event_* keys are removed for users without unfiltered_html; image_class is not
// ... $data is stored as JSON in the gallery row
}
}Reading it back, in includes/class-photoblock.php:
public function get_image_class() {
if ( isset( $this->gallery['image_class'] ) ) {
return $this->gallery['image_class']; // returned raw
}
return '';
}And rendering, in public/partials/photoblocks-public-display.php:
<img
class="pb-image skip-lazy <?php echo $block->get_image_class(); ?>"
src="data:image/png;base64,iVBORw0KGgo...">The value goes in through a tag-stripper that keeps quotes, is stored, comes back raw, and is echoed into a quoted attribute. The <img> also carries a valid inline src, so an injected onload handler fires as soon as the page renders, with no click needed.
Why this is an incomplete fix
This plugin had already had a Contributor-level XSS fixed. CVE-2026-66448 covered versions up to 1.3.3 and was fixed in 1.3.4. Before reporting, I needed to know whether image_class was just that old bug again, so I pulled tags/1.3.3 and tags/1.3.4 from the plugin SVN and diffed them. The admin code and class-photoblock.php were byte-identical. The only change was in photoblocks-public-display.php, where esc_attr() was added to the rel, target and href attributes of the gallery link a few lines below the image. Separately, the 1.3.3 security update had restricted the custom JavaScript fields (custom_event_*) to users with unfiltered_html.
The class attribute on the <img>, in the same file and in the same patch window, was left alone. That is the usual shape of an incomplete fix: the vendor escaped the sinks named in the report and did not go through every other echo in the template.
Reproducing it on a test install
On a local WordPress with a vulnerable version installed, logged in as a Contributor:
-
Open the gallery editor and save a gallery whose
image_classsetting is:text x" onload="alert(document.domain)In the request this sits in the
settingsJSON of the save call, along with the editor’s nonce. -
Put
[photoblocks id=<GALLERY_ID>]in a post. A Contributor cannot publish, but they can submit a post for review. -
View the page, or have an administrator open it to review the post.
The image renders as:
<img class="pb-image skip-lazy x" onload="alert(document.domain)" src="data:image/png;base64,...">The quote closes class, onload becomes a real attribute, and the script runs. I confirmed it live on a local test install of 1.3.4, the latest release at the time; the published advisory lists every version before 1.3.6 as affected.
How to find this in your own code
- Grep for raw echoes inside attributes. In PHP templates, search for
="<?php echoand='<?php echo, and for<?=inside a tag. Any match that is not wrapped inesc_attr(),esc_url()or a value you know is an integer is a lead. - Follow getters back to the source.
echo $block->get_image_class()looks harmless because the escaping question is hidden behind a method. Open the getter. If it returns stored data unchanged, the caller has to escape. - Treat
sanitize_text_field()as “not escaped”. It is fine for storage. When it is the only protection on a value that later reaches an attribute, that is a bug, because quotes survive. - When a security patch lands, review the whole file. Diff the fixed release against the previous one, list the sinks the patch touched, then check every other echo in those files. The ones the patch skipped are where the variants live.
- Check who can write the value. A setting that only
manage_optionscan save is lower risk. One saved behindedit_postsis reachable by Contributors: guest authors, freelance writers, and on some sites anyone who registers, if the default role has been raised above Subscriber.
The fix
Escape on output, for attribute context. The smallest correct change is at the getter or at the echo:
public function get_image_class() {
if ( isset( $this->gallery['image_class'] ) ) {
return esc_attr( $this->gallery['image_class'] );
}
return '';
}Escaping at the echo (<?php echo esc_attr( $block->get_image_class() ); ?>) is the more idiomatic WordPress choice, because the escape sits next to the context it is for. For defence in depth, also validate the setting on save as what it claims to be, a list of CSS class names. sanitize_html_class() applied to each space-separated token does this. The vendor released the fix in 1.3.6.
Impact
The attacker needs an account with at least Contributor rights. That put the bug outside the Patchstack bounty scope, which only takes unauthenticated, Subscriber or Customer-level issues, so it went to WPScan, which accepts Contributor-level XSS and assigns CVEs. CISA’s ADP enrichment scores it CVSS 3.1 6.8 (AV:N/AC:L/PR:H/UI:R/S:U/C:H/I:H/A:H).
A Contributor-level requirement does not make the bug minor. A Contributor’s job is to write content that a more privileged user then looks at, and reviewing pending posts is part of what editors and administrators do. When an administrator’s browser runs the planted script, it runs with the administrator’s session on the admin’s own origin. It can read nonces from wp-admin pages and use them to create a new administrator account, change a user’s email, or install a plugin, which on WordPress means running arbitrary PHP. A stored XSS that reaches an admin is a privilege escalation from Contributor to full site control. It also runs for every ordinary visitor of any page that embeds the gallery.
Disclosure timeline
| Date | Event |
|---|---|
| 2026-08-14 | Reported to WPScan |
| 2026-09-02 | Version 1.3.6 tagged in the plugin SVN with the fix |
| 2026-10-10 | CVE-2026-107323 published |
| 2026-10-14 | This write-up |
References
- WPScan advisory: https://wpscan.com/vulnerability/19a8c2db-fb31-4203-83d6-139b35c93a80/
- CVE record: https://www.cve.org/CVERecord?id=CVE-2026-107323
- Earlier, related fix: https://www.cve.org/CVERecord?id=CVE-2026-66448
- WordPress developer docs, escaping data: https://developer.wordpress.org/apis/security/escaping/
- CWE-79: https://cwe.mitre.org/data/definitions/79.html
Takeaway
Escape for the place the value lands, not the place it came from.
A tag-stripping sanitiser keeps quotes, so anything echoed into an attribute needs esc_attr() on output.