Skip to content

Decode the LearnDash Video URL without reinterpreting it as HTML - #2391

Merged
KMchaudhary merged 1 commit into
developfrom
fix/learndash-admin-dom-xss
Nov 19, 2026
Merged

KMchaudhary merged 1 commit into
developfrom
fix/learndash-admin-dom-xss

Conversation

@KMchaudhary

Copy link
Copy Markdown
Collaborator

What and why

Resolves the CodeQL finding on the v2.11.0 develop→main sync (#2389): "DOM text reinterpreted as HTML" in assets/src/js/learndash/admin.js.

The decode helper that reads the saved LearnDash Video URL used a textarea.innerHTML = value round-trip to decode HTML entities. CodeQL flags assigning page-derived text to innerHTML as a potential XSS sink.

The value is only ever checked against the GoDAM marker shortcode, so a full HTML parse is unnecessary. This replaces the round-trip with a plain string replacement of just the entities WordPress escaping produces (<, >, ", '/', ', &), so the field value is never reinterpreted as HTML. & is decoded last so an already-escaped ampersand is not decoded twice. The now-unused doc parameter is dropped.

Where to look

  • assets/src/js/learndash/admin.js — the decode helper and its single caller.

How to test

npx jest assets/src/js/learndash/admin.test.js — all 14 tests pass, including the case that saves the marker with "-escaped quotes and expects it cleared when the switch is turned off.

Risk

risk: low — behaviour is unchanged for every value the field holds; only the decoding mechanism changed.

🤖 Generated with Claude Code

CodeQL flagged `textarea.innerHTML = value` in the Video URL decode helper
as DOM text reinterpreted as HTML. Replace the textarea round-trip with a
targeted decode of just the entities WordPress escaping produces, so the
field value is never parsed as HTML. `&` is decoded last to avoid
double-decoding.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
15 0 15

⚠️ Warnings (15)

📁 readme.txt (2 warnings)
📍 Line 🔖 Check 💬 Message
0 mismatched_plugin_name Plugin name "GoDAM - Video Hosting for LMS & Online Courses" is different from the name declared in plugin header "GoDAM".
0 readme_parser_warnings_trimmed_section_description The "Description" section is too long and was truncated. A maximum of 2500 characters is supported.
📁 inc/classes/class-media-library-ajax.php (1 warning)
📍 Line 🔖 Check 💬 Message
1643 WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound Hook names invoked by a theme/plugin should start with the theme/plugin prefix. Found: "max_srcset_image_width".
📁 assets/build/pages/video-editor.min.js (1 warning)
📍 Line 🔖 Check 💬 Message
2 react_removed_api This file calls "ReactDOM.findDOMNode", which was removed in React 19 and stops working once WordPress upgrades React. Use a ref on the element instead.
📁 assets/build/css/main.css (1 warning)
📍 Line 🔖 Check 💬 Message
0 EnqueuedStylesScope This style is being loaded in all contexts.
📁 assets/src/libs/analytics.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/11/19/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
📁 assets/build/js/main.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/11/19/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@rudrakshi-gupta

Copy link
Copy Markdown
Member

Reviewed 1d035f3. The fix is fine and removes the CodeQL sink. No blockers.

Checked

  • decode() is plain string replacement now, so the field value never reaches the HTML parser. &amp; is decoded last, so a double-escaped value stays escaped once (&amp;quot; → &quot;), which matches what PHP's html_entity_decode() does with the same input.
  • decode() has a single caller (setupUseGoDAMSwitch()), and dropping the unused doc parameter is safe.
  • I ran the new decode() + isMarker() over the forms the saved value can take:
Saved value Marker?
[video_godam], [video_godam id="12"] ✅
id=&quot;12&quot;, id=&#039;12&#039;, id=&#39;12&#39;, id=&#x27;12&#x27; ✅
id=&#34;12&#34;, id=&#x22;12&#x22; (numeric double quote) ❌
&#91;video_godam id=&quot;12&quot;&#93; (numeric brackets) ❌
https://youtu.be/x?a=1&amp;b=2 ❌, correctly kept

For context, the old textarea.innerHTML round trip wasn't exploitable: a detached <textarea> parses its content as plain text, so nothing runs. Still, switching away from it is the cleanest way to clear the alert.

Nit (optional)

  • The PHP side reads the same value with html_entity_decode( $value, ENT_QUOTES ) (get_marker_video_id()), which decodes every entity, so the numeric forms above count as the marker there but not here. It has no real effect: if the switch is turned off on such a value, apply_use_godam_setting() still clears the marker on save. Only the field wouldn't empty on screen right away. If you want both sides to agree, two more replacements before the &amp; one would cover every numeric entity, still without parsing HTML:
    .replace( /&#(\d+);/g, ( m, n ) => String.fromCodePoint( Number( n ) ) )
    .replace( /&#x([0-9a-f]+);/gi, ( m, n ) => String.fromCodePoint( parseInt( n, 16 ) ) )
    (Out-of-range numbers would make fromCodePoint throw, so cap them or wrap it in a try/catch if you add this.)

Ready to approve from my side.

@KMchaudhary
KMchaudhary merged commit e028992 into develop Nov 19, 2026
4 checks passed
@KMchaudhary
KMchaudhary deleted the fix/learndash-admin-dom-xss branch November 19, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants