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

9.0.0 break inline base64-encoded images #774

Closed
4 tasks done
justrealmilk opened this issue Oct 2, 2023 · 9 comments
Closed
4 tasks done

9.0.0 break inline base64-encoded images #774

justrealmilk opened this issue Oct 2, 2023 · 9 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@justrealmilk
Copy link

Initial checklist

Affected packages and versions

9.0.0

Link to runnable example

No response

Steps to reproduce

Attempt to display

![dreamweaver-32](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAKYUlEQVRYw52Wa4xd11XHf3vv876vedw7c+cV22M7dmziOmlIY5dAST84jYpA5dmStICEKEigtBQF+NLSiioCGkEopVAp6oMkpVWhaqM0QKomNIBLcOIkje069tiel2c8jzv3dc6955y9Nx/uxE6iqFQsaelIW2dr/dbSXmv9xfv+0uG1ZjQYYwCwxmKtRQBC4mjNjjTjx43lFms5bC2zAEIwB5xUiv9xBM8qySUkudGQ9wEkWNi6LMgSOPmYJmkO4okfBoC1GGOLac7Ppyl/ICwHHQWuO3DB1d/IUkhzyHJActqV4i88134179NG/D8AhIAs5c5ear6kBNVyAUZGXYZqRaJShBu6SEcBoDNNmvRJWgmba12amxlbbciNaCrNPZ4nHrMW21j+kQAsQBDH9nN5Zu6ujcLUTInRmRrh6BBOEAwCC4EQYrsCFqzBZJo86RGvb7I2v8byQsxaA6SQ/0SfezqbIv4/Aayh0o3t4w766I4dHtP7pyjWx1CBD2L7XRgLWITdviMABEIK2IbK44TO8irzp5eYX9L0Ynkq2xI/1W2w/uITmmRrcFe+LrrA7/fNE77SR/cfLLHnbfsZ2jWDCn2MNthMI7XBteBZgce2W4FrgdzgkFIpp9QmXXa8dZKb37WbAzeElIfMAb/Kd5UrilnympB3/7W/nQYkif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um42450Mdfu8Tl/CGNmhuDdSyvSrVBqXPugnx5iqLZ3nmqS/ED1xty48/NQOA60s2FrMoT3rPTu4vHRiZmaZQsUjt8cL3qpw5WWJhqYfMQ5BdJsY9pmbb3HwkoTKxQbtlSVM1UIpi0PsKgfIc+kmPzso8a5f6F77yyfgdcyeS+WsA3xkAOJ5gYyFn9WJWre8w/1HfW7y+Mj5JueBRKqZIUWaz4WCMwoiYsNzHOE3aLUPei/BUAYmzLVZzHGGwjkOr3aazvsT6fO/8Nx7s/dzLT3W//7rB9FqAxuWcxdMpvQ6lnTfy1foe/9jI2BjlQomyW2E43Ien6ig5TK4V0oRgwZCCzcnNFj09Tzs/Sydv0ew26bTWufRC/78eezD+lbnnrmX+qsk3Hni+IE9N++uf6t514vHknuW5y/FaY4GV1hKrzSWy1FIUM+zy7mBfcBf7wrvYGb6dsl/D2h6NZIErnSU2mousXFiJn3kk/sOHPtx8x5sFf9MKrJ7P6G4Znn64xfW3RsSdfOyGo+4H9x/1fqdc88dDf4SScx2hU0cpHxDkOibOLtPJFuhlDbZW09Wzx7OHn3+i93dn/jM5yw+xNwXoNAz//Y0OB28P+e6X2yhHUBxR0b7bvJumD/CT5XFzoFhjj1+UEyDot/XlzoY411wWpy68YJ+dO5GdWDnfb/Aj2P8CAHgkcf43tWEAAAAASUVORK5CYII=)

with react-markdown 8.0.7 vs 9.0.0

Expected behavior

Image should display

Actual behavior

Something bad happens resulting in the src value being lost

Runtime

Node v17

Package manager

npm 8

OS

Linux

Build and bundle tools

Next.js

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Oct 2, 2023
@ChristianMurphy
Copy link
Member

Welcome @justrealmilk!
Sorry you ran into a spot of trouble.
Sanitizing URLs is one of the security features of react-markdown.
This is done by the urlTransform option https://github.com/remarkjs/react-markdown#options
The default sanitizer is https://github.com/micromark/micromark/tree/main/packages/micromark-util-sanitize-uri#readme which disallows the data: protocol because it is unsafe.
You are welcome to customize the sanitizer to allow unsafe URLs if you trust them

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2023
@ChristianMurphy ChristianMurphy added the 🙋 no/question This does not need any changes label Oct 2, 2023
@github-actions

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Oct 2, 2023
@justrealmilk
Copy link
Author

ah dang okay thanks urlTransform={(value: string) => value}

@wooorm
Copy link
Member

wooorm commented Oct 2, 2023

Glad it works for you. But note for future readers: This is unsafe!

@justrealmilk
Copy link
Author

How do I make an exception/call the default function to make it more safe?

@wooorm
Copy link
Member

wooorm commented Oct 3, 2023

Least specific to most:

  • You are allowing all URLs. This is always super unsafe.
  • Even if you use the safe default for all URLs except for data URLs, data URLs are super unsafe.
  • If you use the defaults for everything except for images as data URLs, many image formats will be unsafe. GIFs, WebPs, and SVGs for example can include JS.

How to use the default function:

The default function is exposed and documented: https://github.com/remarkjs/react-markdown#defaulturltransformurl. Import it.
Then pass the documented urlTransform option.
Such as this pseudo code:

urlTransform(url) {
  if (someCondition) {
    return myCustomProcessing(url)
  }
  
  return defaultUrlTransform(url)
}

@szszoke
Copy link

szszoke commented Apr 27, 2024

@wooorm could you provide/link to some documentation regarding why this is unsafe?

I tried a few attacks where JS was embedded in image files but they didn't seem to work.

@ChristianMurphy
Copy link
Member

@szszoke there are a lot of reasons why it is a bad idea.
It is also fairly well known, searching the topic turns up many resources.

A selection of them:

@szszoke
Copy link

szszoke commented Apr 27, 2024

Thanks! I'm not disputing that this is an issue, I just wanted to see some concrete examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

4 participants