Repository navigation
Description
Feature Request
Ionic version:
[x] 4.x
Describe the Feature Request
We recently introduced a basic sanitizer which should help Ionic users avoid unintentional XSS vulnerabilities in their applications. Similar to Angular's sanitizer, there exists methods to bypass the sanitize method if a user wants to do something particularly complex that the sanitizer would typically not allow.
Because our sanitizer does not allow every possible combination of markup + styling, it would be good to give users the option to bypass the sanitizer in the event that a) they are certain there are no XSS vulnerabilities (or at least, they know they are responsible for ensuring their code is safe) and b) want to do something complex that the sanitizer can't reliably make sanitary.
Describe Preferred Solution
I would expect the sanitizer to be bypassed if it received an IonicSafeCode as input. Here is how it would look for ion-alert:
const alert = await alertController.create({
header: 'Alert',
subHeader: 'Subtitle',
message: new IonicSafeCode('<a href="https://ionicframework.com" target="_blank">Hello World!</a>')
buttons: ['Cancel', 'Open Modal', 'Delete']
});
Then the sanitizer method would need to check to see if the content it is receiving is of type IonicSafeCode and allow it to pass through.
(I'm open to other class names. IonicSafeCode was the first one that came to mind)
Additional Context
Activity
miqmago commentedon May 15, 2019
Coool feature!! Maybe there is something I can't see right now, but why not allowing SafeHtml as type? So it would be easy to be achieved with something like this:
Also found some customer asking for icons in header, so wouldn't it be nice to have also in
headerandsubHeader?Finally I don't know if it's related, will it be available for toasts too?
liamdebeasi commentedon May 15, 2019
this.domSanitizer.bypassSecurityTrustHtmlis something that is Angular-specific and will not work with other frameworks. There is likely some research to be done into howIonicSafeCodewill interact with Angular's own sanitizer.Regarding the icons in
header, this discussion is best suited for a separate issue.There is already a issue open for HTML content with toasts: #18204
cumpstey commentedon Jan 22, 2020
I spent a while trying to debug before I eventually came across this ticket.
I found that html in the message property wasn't sanitised in 4.0.0-beta7, and was in 4.11.7.
I need to use html with inline styles in the message property, as I'm showing KaTeX markup in the alert and that includes inline styles for element positioning. My fairly fragile workaround, while waiting for a better solution as above, is direct manipulation of the dom. I hope it's useful for anyone else who finds this ticket while waiting for the better solution described above.
liamdebeasi commentedon Feb 12, 2020
Hi everyone,
I am working on this feature and would love some feedback. Here is a dev build you can use to try it out:
5.0.0-dev.202002121951.779ed34.npm i @ionic/[email protected]npm i @ionic/[email protected]Usage on a per-instance basis:
Angular:
React:
Disabling sanitizing across your entire app:
Angular
app.module.tsReact
App.tsxliamdebeasi commentedon Apr 27, 2020
This has been resolved via #20457 and will be in an upcoming release of Ionic Framework.
ionitron-bot commentedon May 27, 2020
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.