Skip to content
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

Image compression of SVG file changes mimetype to image/png #828

Open
ashutosh1206 opened this issue May 12, 2022 · 2 comments
Open

Image compression of SVG file changes mimetype to image/png #828

ashutosh1206 opened this issue May 12, 2022 · 2 comments
Labels
backlog Things that are not actively worked on and won't be in the near future needs-investigation Things that need investigation to properly classify them

Comments

@ashutosh1206
Copy link
Contributor

Noticed that image compression changes the mimetype of an SVG to image/png. Combined with https://github.com/capsulesocial/capsule-orbit/issues/425, the image passes through to the backend successfully.

There's a check before compression step in the post editor (src/components/post/Editor.vue) throwing an error that needs to be disabled:

			if (!isValidFileType(file.type)) {
				this.$toastError(`image of type ${file.type} is invalid`)
				return
			}

To confirm that mimetype changes due to compression, I disabled it and verified the mimetype of the resultant data URL (it was image/svg+xml:

			const reader = new FileReader()
			reader.readAsDataURL(image)
			reader.onload = async (i) => {
				if (i.target !== null && i.target.result !== null) {
					const cid = await addPhotoToIPFS(i.target.result)
					resolve({ cid, url: i.target.result, image, imageName: image.name })
				}
			}

Now I am not sure exactly what happens to the image raw data, because that the image gets rendered correctly on the post reader. I am opening an issue since we should probably check if the image raw data is an SVG after compression, or a PNG. Might need to consider security implications if it's an SVG (how the image is loaded on the reader etc.).

@ashutosh1206 ashutosh1206 added the needs-investigation Things that need investigation to properly classify them label May 12, 2022
@chrispanag
Copy link
Contributor

With cure53, we established that the src field of an image on the browser doesn't allow the execution of any malicious tags. I'll try to read more though about what happens during compression.

@chrispanag
Copy link
Contributor

So... it's actually really interesting why it works with the svg.

It uses the OffscreenCanvas feature of the browser. Basically it renders the image there, and then it performs the necessary operations (this is useful because it leverages GPU acceleration in some operation)

So because it is a canvas, you can render anything you want, even an svg. But the results (apparently - pending confirmation) are png/jpeg, because it is converted afterwards.

@ashutosh1206 ashutosh1206 added the backlog Things that are not actively worked on and won't be in the near future label Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Things that are not actively worked on and won't be in the near future needs-investigation Things that need investigation to properly classify them
Projects
None yet
Development

No branches or pull requests

2 participants