- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(rspack): support getPublicPath #3422
Conversation
🦋 Changeset detectedLatest commit: 4e8ba83 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
} else { | ||
code = `(${this._getPublicPath})()`; | ||
code = `${ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ScriptedAlchemy hey , i see this just call the function before , not sure whether you forget add webpackRequire.p = function(){} or you want to users pass getPublicPath and assign by themself like getPublicPath: function(){ webpackRequire.p = 'https://' }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
originally i had implemented it with the ability to accept arguments, but i think you were concerned about backward compat, so we did not add arguments to the function call. But originally i had intended for this capability to exist, and removed it after you raised some concern many months ago
Stale pull request message |
522f3ec
to
d916eed
Compare
d916eed
to
c13b942
Compare
if (!this._getPublicPath.startsWith('function')) { | ||
code = `${ | ||
compiler.webpack.RuntimeGlobals.publicPath | ||
} = new Function(${JSON.stringify(this._getPublicPath)})()`; | ||
} = new Function(${JSON.stringify(sanitizedPublicPath)})()`; |
Check warning
Code scanning / CodeQL
Improper code sanitization Medium
improperly sanitized value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 14 days ago
To fix the problem, we need to ensure that the sanitizedPublicPath
is properly sanitized before being used in the dynamic code execution. We can enhance the escapeUnsafeChars
function to cover a broader range of potentially dangerous characters and sequences. Additionally, we should ensure that the sanitizedPublicPath
is properly escaped before being passed to JSON.stringify
.
- Enhance the
escapeUnsafeChars
function to cover more potentially dangerous characters. - Use the enhanced
escapeUnsafeChars
function to sanitizethis._getPublicPath
. - Ensure that the sanitized value is properly escaped before being used in dynamic code execution.
-
Copy modified line R21 -
Copy modified line R41
@@ -20,3 +20,3 @@ | ||
function escapeUnsafeChars(str: string) { | ||
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, (x) => charMap[x]); | ||
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029\\]/g, (x) => charMap[x]).replace(/['"]/g, (x) => '\\' + x); | ||
} | ||
@@ -40,3 +40,3 @@ | ||
compiler.webpack.RuntimeGlobals.publicPath | ||
} = new Function(${JSON.stringify(sanitizedPublicPath)})()`; | ||
} = new Function(${JSON.stringify(escapeUnsafeChars(sanitizedPublicPath))})()`; | ||
} else { |
Description
rspack plugin support getPublicPath
Related Issue
Types of changes
Checklist