Skip to content

feat(all): add ability to eject from Ionic sanitizer - #20457

Merged
liamdebeasi merged 12 commits into
masterfrom
sanitizer-eject
Apr 27, 2020
Merged

liamdebeasi merged 12 commits into
masterfrom
sanitizer-eject

Conversation

@liamdebeasi

@liamdebeasi liamdebeasi commented Feb 12, 2020 •

Copy link
Copy Markdown
Contributor

blocks ionic-team/ionic-docs#1329

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: #18277

What is the new behavior?

  • Added IonicSafeString, a class that users can provide to components that allow for custom HTML in order to selectively bypass our sanitizer.
  • Added a sanitizerEnabled config that can be used to disable/enable our sanitizer across a user's whole application.

Does this introduce a breaking change?

  • Yes
  • No

Usage

Usage on a per-instance basis:

Angular:

import { IonicSafeString } from '@ionic/angular';

...

async openAlert() {
  const alert = await this.alertController.create({
      header: 'Alert',
      subHeader: 'Subtitle',
      message: new IonicSafeString('<img src="x" onerror="alert("Hello!");">'),
      buttons: ['OK']
});

    await alert.present();
  }

React:

import { IonicSafeString } from '@ionic/react';

...

const Home: React.FC = () => {
  const [showAlert1, setShowAlert1] = useState(false);
  
  return (
    <IonPage>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Blank</IonTitle>
        </IonToolbar>
      </IonHeader>
      <IonContent>
        <IonButton onClick={() => setShowAlert1(true)} expand="block">Show Alert 1</IonButton>
        <IonAlert
          isOpen={showAlert1}
          onDidDismiss={() => setShowAlert1(false)}
          header={'Alert'}
          subHeader={'Subtitle'}
          message={new IonicSafeString('<img src="x" onerror="alert(document.cookie);">')}
          buttons={['OK']}
        />
      </IonContent>
    </IonPage>
  );
};

Disabling sanitizing across your entire app:

Angular
app.module.ts

...
IonicModule.forRoot({
  sanitizerEnabled: false
})
...

React
App.tsx

import { setupConfig } from '@ionic/react';

setupConfig({
  sanitizerEnabled: false
});

@ionitron-bot ionitron-bot Bot added package: angular @ionic/angular package package: core @ionic/core package labels Feb 12, 2020
@liamdebeasi
liamdebeasi marked this pull request as ready for review February 12, 2020 20:45
@liamdebeasi liamdebeasi changed the title feat(): add ability to eject from Ionic sanitizer feat(all): add ability to eject from Ionic sanitizer Mar 26, 2020
@brandyscarney

Copy link
Copy Markdown
Member

Should we add this to the usage, with a big warning of "use at your own risk" or something?

@liamdebeasi

Copy link
Copy Markdown
Contributor Author

@brandyscarney

Copy link
Copy Markdown
Member

@liamdebeasi Ahh always ahead of me. Ok I'll review that next!

@liamdebeasi
liamdebeasi merged commit fa9ddc9 into master Apr 27, 2020
@liamdebeasi
liamdebeasi deleted the sanitizer-eject branch April 27, 2020 20:03
@MuhAssar

MuhAssar commented May 1, 2020

Copy link
Copy Markdown

I'm just curious why it is not called IonSafeString like the rest of Ionic API?

devinshoemaker added a commit to nxtend-team/nxtend that referenced this pull request May 5, 2020
In Ionic 5.1.0, the Ionic team added a feature that allows users to eject from the Ionic sanitizer application-wide. This PR adds a flag to the application schematic to implement this new feature.

ionic-team/ionic-framework#20457
devinshoemaker added a commit to nxtend-team/nxtend that referenced this pull request May 5, 2020
In Ionic 5.1.0, the Ionic team added a feature that allows users to eject from the Ionic sanitizer application-wide. This PR adds a flag to the application schematic to implement this new feature.

ionic-team/ionic-framework#20457
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants