Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.
This repository was archived by the owner on May 4, 2022. It is now read-only.

Security risks for ion-alert and other components #900

Open

Description

@ionitron-bot

Original issue by @cjorasch on 2018-06-07T01:34:47Z

Feature Request

Ionic Info

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

System:

    Node : v8.9.1
    npm  : 5.7.1
    OS   : macOS High Sierra

Misc:

    backend : pro

Describe the Feature Request
Components that use innerHTML to set html content based on property values create a potential security risk when used with user entered content.

From: https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML

Warning: If your project is one that will undergo any form of security review, using innerHTML most likely will result in your code being rejected. For example, if you use innerHTML in a browser extension and submit the extension to addons.mozilla.org, it will not pass the automated review process.

The use of innerHTML with external Prop() values is used by <ion-alert>, <ion-refresher-content>, <ion-infinite-scroll-content>, <ion-searchbar> and maybe others.

In addition to the security risk there is also potential problems due to html escaping if the string content contains valid html characters (<. >, &, ...) that were entered by the end user.

Describe Preferred Solution
Change the data type of the property from string to JSX.Element and use normal JSX rendering. This allows the component to still provide rich html rendering without risking html injection. String values could still be used for simple messages.

For example, in <ion-alert>:

// Current ion-alert
@Prop() message?: string;
<div id={msgId} class="alert-message" innerHTML={this.message}></div>

// Proposed ion-alert
@Prop() message?: JSX.Element;
<div id={msgId} class="alert-message">{this.message}</div>

// Calling with JSX
const alert = await alertController.create({
    message: <span>Hello <b>{this.name}</b>!</span>
});

// Calling with simple string
const alert = await alertController.create({
    message: 'Hello!'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions