Skip to content

[DO NOT MERGE] docs: improve typedoc documentation, fix JSDoc, upgrade deps, and clean up API surface#2958

Draft
Michael Pham (michaelphamcf) wants to merge 1 commit intomasterfrom
refactor/docs-clean
Draft

[DO NOT MERGE] docs: improve typedoc documentation, fix JSDoc, upgrade deps, and clean up API surface#2958
Michael Pham (michaelphamcf) wants to merge 1 commit intomasterfrom
refactor/docs-clean

Conversation

@michaelphamcf
Copy link
Copy Markdown
Contributor

Summary

Description

Motivation and Context

PR Checklist

  • I have read the CONTRIBUTING.md file
  • All commits follow conventional commits
  • Documentation is updated (if necessary)
  • PR doesn't contain any sensitive information
  • There are no breaking changes

…an up API surface

Comprehensive documentation and API cleanup branch extracted cleanly from
refactor/docs (which had rebasing issues with master).

See docs/refactor-docs-changelog.md for a detailed breakdown of all changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
var newVersion = select.value
var subPath = pathSegments.slice(cmIdx + 2).join('/')
var newUrl = docsBase + '/' + newVersion + '/' + subPath
window.location.href = newUrl

Check failure

Code scanning / CodeQL

DOM text reinterpreted as HTML High documentation

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix

AI 6 days ago

In general, to fix this kind of issue you should (1) validate or whitelist the untrusted value (select.value) against the expected set of safe options, and (2) ensure that the constructed URL cannot become an arbitrary or cross-origin URL (e.g., javascript:..., https://evil.com/...). Since the code already has a known set of versions (versions array plus possibly currentVersion), we can derive an explicit whitelist and only navigate if the chosen value is in that list. Additionally, we can construct the new URL using the existing path segments and the browser’s URL parser to avoid protocol or origin changes.

The minimal, non-breaking change is to: inside the then(function (versions) { ... }) block, define a validVersions array that contains the allowed version values (from versions, plus currentVersion if it is not already in the list). Then, in the change event listener, check whether newVersion is included in validVersions; if not, abort. When constructing newUrl, build it as a relative path anchored to the current origin using the URL constructor, so even if an unexpected string slipped in, it cannot change protocol or origin. Concretely, we will: (a) introduce var validVersions = versions.slice(); after we know versions, optionally pushing currentVersion if needed; (b) update the change handler to return early if validVersions.indexOf(newVersion) === -1; and (c) replace the simple string concatenation var newUrl = docsBase + '/' + newVersion + '/' + subPath with var newUrl = new URL(docsBase + '/' + newVersion + '/' + subPath, window.location.origin).toString();. All changes are within docs/plugins/version-selector/version-selector.js and do not alter the external behavior for valid version values.

Suggested changeset 1
docs/plugins/version-selector/version-selector.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/docs/plugins/version-selector/version-selector.js b/docs/plugins/version-selector/version-selector.js
--- a/docs/plugins/version-selector/version-selector.js
+++ b/docs/plugins/version-selector/version-selector.js
@@ -23,6 +23,12 @@
       .then(function (versions) {
         if (!versions || !versions.length) return
 
+        // Build a whitelist of valid versions from the data source
+        var validVersions = versions.slice()
+        if (validVersions.indexOf(currentVersion) === -1) {
+          validVersions.push(currentVersion)
+        }
+
         var wrapper = document.createElement('div')
         wrapper.className = 'tsd-version-selector'
 
@@ -57,8 +63,13 @@
 
         select.addEventListener('change', function () {
           var newVersion = select.value
+          // Only allow navigation to known-safe versions
+          if (validVersions.indexOf(newVersion) === -1) {
+            return
+          }
           var subPath = pathSegments.slice(cmIdx + 2).join('/')
-          var newUrl = docsBase + '/' + newVersion + '/' + subPath
+          var relativePath = docsBase + '/' + newVersion + '/' + subPath
+          var newUrl = new URL(relativePath, window.location.origin).toString()
           window.location.href = newUrl
         })
 
EOF
@@ -23,6 +23,12 @@
.then(function (versions) {
if (!versions || !versions.length) return

// Build a whitelist of valid versions from the data source
var validVersions = versions.slice()
if (validVersions.indexOf(currentVersion) === -1) {
validVersions.push(currentVersion)
}

var wrapper = document.createElement('div')
wrapper.className = 'tsd-version-selector'

@@ -57,8 +63,13 @@

select.addEventListener('change', function () {
var newVersion = select.value
// Only allow navigation to known-safe versions
if (validVersions.indexOf(newVersion) === -1) {
return
}
var subPath = pathSegments.slice(cmIdx + 2).join('/')
var newUrl = docsBase + '/' + newVersion + '/' + subPath
var relativePath = docsBase + '/' + newVersion + '/' + subPath
var newUrl = new URL(relativePath, window.location.origin).toString()
window.location.href = newUrl
})

Copilot is powered by AI and may make mistakes. Always verify output.
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