Skip to content

Node.js based forum software built for the modern web

fix(activitypub): prevent XSS via intent templates and plugin upgrade bypass

Julian Lam2ba41197d5a6
diff --git a/public/src/modules/intents.js b/public/src/modules/intents.js
index b060d138f6..878f3aa0c2 100644
--- a/public/src/modules/intents.js
+++ b/public/src/modules/intents.js
@@ -235,7 +235,15 @@ export async function trigger(intent, parameters) {
url = url?.replaceAll(/\{[^}]+\}/g, '');
if (url) {
- window.location.href = url;
+ // Validate URL scheme to prevent XSS via javascript: data: etc.
+ try {
+ const parsed = new URL(url);
+ if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
+ window.location.href = url;
+ }
+ } catch (e) {
+ // Invalid URL, silently ignore
+ }
}
});
diff --git a/src/controllers/write/intents.js b/src/controllers/write/intents.js
index 9c6da6acce..6bd1efbe6d 100644
--- a/src/controllers/write/intents.js
+++ b/src/controllers/write/intents.js
@@ -38,6 +38,15 @@ Intents.query = async (req, res) => {
intents = webfinger._raw.links.reduce((memo, link) => {
if (link.rel.startsWith(prefix)) {
const intent = link.rel.slice(prefix.length).toLowerCase();
+ // Reject non-http/https URLs to prevent XSS via javascript: data: etc.
+ try {
+ const parsed = new URL(link.template);
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
+ return memo; // silently skip untrusted schemes
+ }
+ } catch (e) {
+ return memo; // invalid URL, skip
+ }
memo[intent] = link.template;
}
return memo;
diff --git a/src/plugins/install.js b/src/plugins/install.js
index 395ee5be67..4be3dafa80 100644
--- a/src/plugins/install.js
+++ b/src/plugins/install.js
@@ -125,6 +125,7 @@ module.exports = function (Plugins) {
packageManagerCommands[packageManager][command],
pkgName + (command === 'install' && version ? `@${version}` : ''),
'--save',
+ '--ignore-scripts',
];
if (process.platform === 'win32') {