Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/pages/angular/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Below is a list of config options that Ionic uses.
| `popoverLeave` | `AnimationBuilder` | Provides a custom leave animation for all `ion-popover`, overriding the default "animation".
| `refreshingIcon` | `string` | Overrides the default icon in all `<ion-refresh-content>` components.
| `refreshingSpinner` | `SpinnerTypes` | Overrides the default spinner type in all `<ion-refresh-content>` components.
| `sanitizerEnabled` | `boolean` | If `true`, Ionic will enable a basic DOM sanitizer on component properties that accept custom HTML.
| `spinner` | `SpinnerTypes` | Overrides the default spinner in all `<ion-spinner>` components.
| `statusTap` | `boolean` | If `true`, clicking or tapping the status bar will cause the content to scroll to the top.
| `swipeBackEnabled` | `boolean` | If `true`, Ionic will enable the "swipe-to-go-back" gesture across the application.
Expand Down
1 change: 1 addition & 0 deletions src/pages/react/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Below is a list of config options that Ionic uses.
| `popoverLeave` | `AnimationBuilder` | Provides a custom leave animation for all `ion-popover`, overriding the default "animation".
| `refreshingIcon` | `string` | Overrides the default icon in all `<ion-refresh-content>` components.
| `refreshingSpinner` | `SpinnerTypes` | Overrides the default spinner type in all `<ion-refresh-content>` components.
| `sanitizerEnabled` | `boolean` | If `true`, Ionic will enable a basic DOM sanitizer on component properties that accept custom HTML.
| `spinner` | `SpinnerTypes` | Overrides the default spinner in all `<ion-spinner>` components.
| `statusTap` | `boolean` | If `true`, clicking or tapping the status bar will cause the content to scroll to the top.
| `swipeBackEnabled` | `boolean` | If `true`, Ionic will enable the "swipe-to-go-back" gesture across the application.
Expand Down
81 changes: 80 additions & 1 deletion src/pages/techniques/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,83 @@ To learn more about the built-in protections that React and JSX provide, see the

Vue does not provide any type of sanitizing methods built in. It is recommended that developers use a package such as [sanitize-html](<https://www.npmjs.com/package/sanitize-html>).

To learn more about the security recommendations for binding to directives such as `v-html`, see the [Vue Syntax Guide](https://vuejs.org/v2/guide/syntax.html#Raw-HTML).
To learn more about the security recommendations for binding to directives such as `v-html`, see the [Vue Syntax Guide](https://vuejs.org/v2/guide/syntax.html#Raw-HTML).

## Ejecting from the built-in sanitizer

For developers who wish to add complex HTML to components such as `ion-toast`, they will need to eject from the sanitizer that is built into Ionic Framework. Developers can either disable the sanitizer across their entire app or bypass it on a case-by-case basis.

> Bypassing sanitization functionality can make your application vulnerable to <a href="https://en.wikipedia.org/wiki/Cross-site_scripting" target="_blank" rel="noreferrer">XSS attacks</a>. Please exercise extreme caution when disabling the sanitizer.

### Disabling the sanitizer via config

Ionic Framework provides an application config option called `sanitizerEnabled` that is set to `true` by default. Set this value to `false` to globally disable Ionic Framework's built in sanitizer. Please note that this does not disable any sanitizing functionality provided by other frameworks such as Angular.

### Bypassing the sanitizer on a case-by-case basis

Developers can also choose to eject from the sanitizer in certain scenarios. Ionic Framework provides the `IonicSafeString` class that allows developers to do just that.

#### Usage

<docs-tabs>
<docs-tab tab="angular">

```typescript
import { IonicSafeString, ToastController } from '@ionic/angular';

...

constructor(private toastController: ToastController) {}

async presentToast() {
const toast = await this.toastController.create({
message: new IonicSafeString('<ion-button>Hello!</ion-button>'),
duration: 2000
});
toast.present();
}

```
</docs-tab>
<docs-tab tab="javascript">

```javascript
import { IonicSafeString } from '@ionic/core';

...

const async presentToast = () => {
const toast = document.createElement('ion-toast');
toast.message = new IonicSafeString('<ion-button>Hello!</ion-button>');
toast.duration = 2000;

document.body.appendChild(toast);
return toast.present();
}

```
</docs-tab>
<docs-tab tab="react">

```typescript
import React, { useState } from 'react';
import { Animation, IonButton, IonContent, IonicSafeString, IonToast } from '@ionic/react';

export const ToastExample: React.FC = () => {
const [showToast, setShowToast] = useState(false);

return (
<IonContent>
<IonButton onClick={() => setShowToast(true)} expand="block">Show Toast</IonButton>
<IonToast
isOpen={showToast}
onDidDismiss={() => setShowToast(false)}
message={new IonicSafeString('<ion-button>Hello!</ion-button>')}
duration={2000}
/>
</IonContent>
)
};
```
</docs-tab>
</docs-tabs>