ActivityPub-federated video streaming platform using P2P directly in your web browser
Refuse remote svg images
Chocobozzzae2b2ddd4c9b
diff --git a/packages/tests/src/server-helpers/image.ts b/packages/tests/src/server-helpers/image.tsindex 59b4c27218..70d02cbbcd 100644--- a/packages/tests/src/server-helpers/image.ts+++ b/packages/tests/src/server-helpers/image.ts@@ -118,6 +118,20 @@ describe('Image helpers', function () {expect(metadata.pages).to.equal(1)})+ it('Should refuse to process a SVG file with processImage()', async function () {+ const input = join(tmpdir(), 'not-really-an-image.svg')+ await writeFile(input, '<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>')++ try {+ await processImage({ path: input, destination: join(imageDestDir, 'out.svg'), keepOriginal: true })+ expect.fail('Should not process a SVG file with processImage()')+ } catch (err) {+ expect(err.message).to.contain('processSVG')+ } finally {+ await remove(input)+ }+ })+after(async function () {await remove(imageDestDir)})diff --git a/server/core/helpers/image-utils.ts b/server/core/helpers/image-utils.tsindex de257a2a17..1b964c5592 100644--- a/server/core/helpers/image-utils.ts+++ b/server/core/helpers/image-utils.ts@@ -47,6 +47,11 @@ export async function processImage (options: {throw new Error('Input path must be different from output path.')}+ // Defensive check: SVG must always go through processSVG() to be sanitized+ if (extension === '.svg' || getLowercaseExtension(destination) === '.svg') {+ throw new Error('SVG images must be sanitized using processSVG(), not processImage().')+ }+logger.debug('Processing image %s to %s.', path, destination)await sharpProcessor({ path, destination, newSize, inputExt: extension, animated: extension.toLowerCase() === '.gif' })diff --git a/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts b/server/core/lib/activitypub/videos/shared/object-to-model-attributes.tsindex c5454c8799..71cfa5a36c 100644--- a/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts+++ b/server/core/lib/activitypub/videos/shared/object-to-model-attributes.ts@@ -42,7 +42,7 @@ import {MVideoUUID} from '@server/types/models/index.js'import { decode as magnetUriDecode } from 'magnet-uri'-import { basename, extname } from 'path'+import { basename } from 'path'import { getDurationFromActivityStream } from '../../activity.js'export function getTagsFromObject (videoObject: VideoObject) {@@ -252,9 +252,11 @@ export function getStoryboardAttributeFromObject (video: MVideoId, videoObject:if (!storyboard) return undefinedconst url = arrayify(storyboard.url).find(u => MIMETYPES.IMAGE.MIMETYPE_EXT[u.mediaType])+ if (!url) return undefinedreturn {- filename: generateImageFilename(extname(url.href)),+ // Derive the extension from the validated mediaType, not the remote URL+ filename: generateImageFilename(getExtFromMimetype(MIMETYPES.IMAGE.MIMETYPE_EXT, url.mediaType)),totalHeight: url.height,totalWidth: url.width,spriteHeight: url.tileHeight,