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

Sanitise raw HTML #422

Open
AJamesPhillips opened this issue Feb 7, 2022 · 2 comments
Open

Sanitise raw HTML #422

AJamesPhillips opened this issue Feb 7, 2022 · 2 comments

Comments

@AJamesPhillips
Copy link

Related to the suggestion for a sanitise function in #225 (comment), and issue #313 and PR #406. A function to sanitise the raw HTML would be useful to enable specifying a white list of tags, their attributes and the attribute's values. In my current use case I would like to allow:

  • anchor tags and their href but nothing else
  • iframes, but only if they have a src url with origin "https://platform.twitter.com" for embedded tweets
  • img tags but only their href, and style attribute's width and height properties.
    And deny all other HTML tags, attributes and attribute values.

Would there be interest in supporting such a function?

@AJamesPhillips
Copy link
Author

For any one else interested I've simplified the tweet embedding to:

<tweet id="801270269184647168" />
const MARKDOWN_OPTIONS: MarkdownToJSX.Options =
{
    overrides:
    {
        // ...

        // If there is any text inside the script tag then render this, otherwise render nothing.
        script: (props: { children: string }) => props.children,
        iframe: (props: { children: string }) => props.children,

        tweet: (props: { id: string }) =>
        {
            const src = `https://platform.twitter.com/embed/Tweet.html?dnt=false&frame=false&hideCard=false&hideThread=false&id=${props.id}&lang=en-gb&theme=light&widgetsVersion=0a8eea3%3A1643743420422&width=400px"`

            return <iframe
                src={src}
                scrolling="no"
                frameBorder={0}
                allowTransparency={true}
                allowFullScreen={true}
                style={{ width: 401, height: 624 }}
            />
        },
        // ...
    },
}

@Innei
Copy link

Innei commented Aug 6, 2022

Hello, Is there any progress here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants