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

Safelist to allow image elements in href attributes for SVGs #49

Open
rebeccahum opened this issue May 25, 2021 · 3 comments
Open

Safelist to allow image elements in href attributes for SVGs #49

rebeccahum opened this issue May 25, 2021 · 3 comments

Comments

@rebeccahum
Copy link

Since I don't think this is currently possible, it would be nice to be able to be able to use setAllowedAttrs() to detect a starting pattern inside a href attribute like data:image/*.

e.g. This gets false positive flagged:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 735 70" width="735" height="70">
	<defs>
		<image width="735" height="70" id="img1" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUrPcSqAAAAABJRU5ErkJggg=="/>
	</defs>
</svg>
@ohader
Copy link
Contributor

ohader commented Aug 8, 2021

As far as I understood, it's not about the attribute name (like href), but about declaring allowed values or value patterns?

I've been working on a DOM-base sanitizer for HTML, recently - it seems some concepts could be reused here as well to introduce custom Behavior. Please have a look to the example at https://github.com/typo3/html-sanitizer#example--api


$hrefAttr = (new Behavior\Attr('href'))
    ->addValues(new Behavior\RegExpAttrValue('#^https?://#'));

... would allow to declare an expected prefix, e.g. https:// or data:image/.+


$hrefAttr = (new Behavior\Attr('href'))
    ->addValues(new Behavior\ ClosureAttrValue(function (string $value): bool) {
        // custom logic, decoding base64 string, check mime-type
        return true; // in case everything is fine - otherwise reject with `false`
    });

... would allow to declare individual handling and delegate to some other service implementation


Just wanted to share my ideas on that topic... 😉

@darylldoyle
Copy link
Owner

Interesting, so I guess you're looking for a way to filter the isHrefSafeValue() method?

I think that could be a good addition, my concern was always that people could allow things without having context on why they're not allowed by default. I'll have a look into this.

@ohader I'd love to hear more about that, do you have that code anywhere that I can look into?

@benjiwheeler
Copy link

I'm a bit confused -- when I use the project author's online demo at https://svg.enshrined.co.uk/ , your code comes through fine. What am I missing?

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

No branches or pull requests

4 participants