Skip to content

Image URL replacement passes an integer cache token to the Optimole SDK #1187

Closed

Description

@pirate-bot

Summary

During image URL replacement, an integer cache token reaches the SDK method that creates an image, which requires a string. The resulting uncaught TypeError can interrupt frontend requests that resolve an image URL, including requests made while generating SEO image metadata.

Customer context

Product / area: Optimole WP image URL replacement
Version: Optimole WP 4.2.16; bundled Optimole PHP SDK 1.2.4
Environment: WordPress 7.1.3; PHP 8.4.26
Integration / third party: Rank Math image metadata resolution appears in the reported stack
Reported error / symptom: createImage() received an integer for $cacheBuster, which is typed as a string
Impact: 16 crash occurrences on 1 site in the report window; affected frontend requests can fail.

Reproduction notes

The reported stack shows Rank Math requesting an attachment image, followed by Optimole's image-downsize and URL replacement filters, where normalize_image() passes the active cache token to Optimole::image(). The production token value was not captured and the failure was not independently reproduced. An integer returned by the cache-token lookup is the reported failure condition.

Diagnosis

Conclusion

The product passes the result of its active-cache-token lookup directly into the Optimole SDK image factory. The getter can return a value stored in an individual-token transient or the main setting without a type check. The pinned SDK 1.2.4 source has a string-typed $cacheBuster parameter on createImage(), consistent with the production TypeError when the returned value is an integer. The source indicates the product boundary can pass through a non-string token; the production token's origin is unknown.

Where this likely occurs

  • inc/url_replacer.php — Optml_Url_Replacer::normalize_image() approx. line 271 passes get_active_cache_booster() directly as the second argument to Optimole::image().
  • inc/url_replacer.php — Optml_Url_Replacer::get_active_cache_booster() approx. lines 332–334 returns an individual transient entry or the supplied main cache-buster value without enforcing a string type.
  • inc/settings.php — Optml_Settings::clear_cache() approx. lines 833–843 stores the API token in settings or the individual-token transient after checking that the token key exists.
  • composer.lock — lines 10–15 pin codeinwp/optimole-sdk v1.2.4. Its upstream Optimole::createImage() declaration at the pinned source has a string-typed $cacheBuster parameter; the dependency's vendor directory is not present in this workspace clone.

Engineering notes

The reported request path is image URL replacement during Rank Math thumbnail resolution. The plugin's token getter documents a string return, but it returns stored values without validating their runtime type. The telemetry confirms an integer reached the strict SDK parameter; it does not identify whether the value originated in the API response, settings, or transient state. The shared SDK signature itself is consistent with the intended string contract.

Test coverage status

tests/test-replacer.php configures string cache-buster settings at approx. lines 142–143. No relevant coverage for integer individual cache tokens or the get_active_cache_booster() return type was found during inspection.

What to verify or explore next

  • May be worth checking the reported cache-token value and how it entered the individual-token transient or main setting.
  • If reproducible, checking image replacement with an integer token may confirm the failing path.
  • The plugin's tests could be checked for behavior with API responses containing numeric token values.

Unknowns / follow-up

The production cache-token value and its origin are unavailable. The pinned dependency source was verified externally because its vendor code is not included in the workspace clone.

Confidence

Confidence: 84/100

Two defects are supported by the reported traces and source: the SDK reads cached post counts as an array despite a historical scalar-to-array transient schema change, and Optimole passes a dynamic cache token directly to a string-typed SDK method. The two missing-file crashes are not confirmed source defects: both target files exist in SDK 3.3.65 and the require is guarded by is_file(), pointing instead to runtime file availability or permissions. No open matching GitHub issues were found for the two confirmed defects.

Crash telemetry

Occurrences 16
Distinct sites 1
First seen 2026-10-12 16:54 UTC
Last seen 2026-10-17 16:38 UTC
Crash location product:vendor/codeinwp/optimole-sdk/src/Optimole.php:124
Request context frontend
Inside Themeisle SDK no
Product versions 4.2.16
WP versions 7.1.3
PHP versions 8.4.26
SDK versions 3.3.66

Source: automated crash report — optimole-wp, fingerprint 07ac0ca5eb14b5c91e9cb74a0206ee4b
Generated by bug-report-triage (ID: bug-report-triage_6ad460f41a3711.50580606)

Activity

  1. added theissue type on Oct 18, 2026
  2. added
    bugThis label could be used to identify issues that are caused by a defect in the product.
    on Oct 19, 2026
  3. self-assigned this
    on Oct 20, 2026
  4. kushh23 commented on Oct 20, 2026

    @kushh23
    Contributor

    🧪 QA steps and test links

    When one image has its own Optimole cache token stored as a number (what clearing a single image's cache can store when the service answers with a numeric token), any page that shows that image through WordPress, such as a featured image or an SEO plugin's image tags, ends in a critical error. Normal use can't force a numeric token, so the steps set one with a Code Snippet.

    Requires: a site connected to Optimole and the Code Snippets plugin, for the steps outside the links.

    Link Build Bot check
    Reproduce the bug Optimole 4.2.17 (released) ✅ Reproduced: the page shows "There has been a critical error on this website." and debug.log has the TypeError below
    Verify the fix PR #1189 build c142a27 ✅ Fixed: the page loads, the featured image URL contains /cb:12345/, no PHP errors

    In the links:

    • Steps 1 to 4 are already done (with photo-one.jpg), and the links open on the test page.
    • Optimole is connected with a placeholder account and the token is set by the setup instead of a Code Snippet, so the images show as broken. Check the page loads and the image URLs.
    • Tools → QA Logs shows debug.log.

    Reproduce on Optimole 4.2.17:

    1. Media → Add New Media File, upload any image and note its file name (for example photo-one.jpg).
    2. Pages → Add New Page, set that image as the Featured image, and publish.
    3. Snippets → Add New, title "QA numeric Optimole token", code below with your file name, then Save and Activate:
      add_action( 'init', function () { set_transient( '_optml_cache_tokens_individual', [ crc32( 'photo-one.jpg' ) => 12345 ], DAY_IN_SECONDS ); } );
    4. View the page.
    • Bug: "There has been a critical error on this website." debug.log shows Uncaught TypeError: Optimole\Sdk\Optimole::createImage(): Argument #2 ($cacheBuster) must be of type string, int given.
    • Fixed: the page loads, and the featured image's URL contains /cb:12345/.
    Edge cases
    • The same image only inside the page content (no featured image): on 4.2.17 the page loads but none of its images are served from Optimole. Fixed: every image is served from Optimole, and that one carries /cb:12345/.
    • Another image on the same page without a token: served from Optimole as usual, with no cb: part.
    • Optimole lazy load on: the page loads, and the image's lazy-load URL carries /cb:12345/.
    • Rank Math or Yoast active with that image as featured image: the post loads with no critical error (the crash report came from Rank Math's image tags).
    • Deactivate the snippet and clear Optimole's cached images in its settings: images load with the global token, no errors.

    Fix: #1189 (open)

  5. pirate-bot commented on Oct 20, 2026

    @pirate-bot
    CollaboratorAuthor

    QA agent — 🟢 Passing checks · Numeric cache tokens no longer crash image URL replacement in the tested paths.

    The base build reproduced the reported TypeError and HTTP 500 responses. With the candidate, featured images, Rank Math metadata, content images and lazy-load URLs retain the numeric token and the pages load. Both added tests and a 30-case token matrix pass. Account and cache-service responses were simulated; live CDN delivery was not tested.

    Worth a human look

    1. Check cache clearing and image delivery with a live Optimole account.
    Checks (4 passed)
    • ✅ A frontend page with a featured image whose individual cache token is integer 12345 loads without a TypeError, and the image URL, including Rank Math image metadata, carries /cb:12345/.
    • ✅ Content-only image replacement completes for an integer individual token, preserving /cb:12345/ for that image while an image without an individual entry uses the configured main string token.
    • ✅ With Optimole lazy loading enabled, a content image with integer individual token 12345 is emitted with a lazy-load Optimole URL carrying /cb:12345/ and the frontend request completes without a TypeError.
    • ✅ Cache-token selection returns strings for main and individual scalar tokens, preserves the main token for unmatched images, and safely uses an empty token and SDK default for non-scalar selected values; affected frontend requests still complete.

    Full report, evidence and session trail

  6. added a commit that references this issue on Oct 20, 2026
    217bb57
  7. pirate-bot commented on Nov 2, 2026

    @pirate-bot
    CollaboratorAuthor

    🎉 This issue has been resolved in version 4.2.18 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

  8. added
    releasedIndicate that an issue has been resolved and released in a particular version of the product.
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugThis label could be used to identify issues that are caused by a defect in the product.bug-reportbug-report-triagecrash-reportreleasedIndicate that an issue has been resolved and released in a particular version of the product.

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions