fix(tools-api): pasteConfig.tags now supports a sanitize config by robonetphy · Pull Request #2100 · codex-team/editor.js · GitHub
Skip to content

fix(tools-api): pasteConfig.tags now supports a sanitize config#2100

Merged
neSpecc merged 30 commits into
nextfrom
fix/xss-problem
Nov 21, 2022
Merged

fix(tools-api): pasteConfig.tags now supports a sanitize config#2100
neSpecc merged 30 commits into
nextfrom
fix/xss-problem

Conversation

@robonetphy

@robonetphy robonetphy commented Jul 16, 2022

Copy link
Copy Markdown
Member

depends on next version of image tool and simple-image tool

@neSpecc

neSpecc commented Jul 25, 2022

Copy link
Copy Markdown
Member

@jorgectf

Copy link
Copy Markdown
Contributor

Thank you for addressing this issue! FWIW, I'd suggest using tools focused on XSS sanitization such as dompurify.

@robonetphy

Copy link
Copy Markdown
Member Author

I think, the best soultuion is to support our sanitization config at the pasteConfig.tags configuration:

  static get pasteConfig() {
    return {
      tags: [ 'img[src]' ],  // <-- all attributes except 'src' will be stripped
    };
  }

@neSpecc I tried this solution but in that case, the configuration for sanitisation is as below:

{
    "p": true,
    "h1": true,
    "h2": true,
    "h3": true,
    "h4": true,
    "h5": true,
    "h6": true,
    "img[src]": true,
    "pre": true,
    "b": {},
    "i": {},
    "a": {
        "href": true,
        "target": "_blank",
        "rel": "nofollow"
    },
    "mark": {
        "class": "cdx-marker"
    },
    "code": {
        "class": "inline-code"
    },
    "br": {}
}```
and in that case, if I paste this correct configuration.
`<img src='https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg'/>`
it's not working. the sanitized data comes empty and it pastes as text.

@robonetphy

robonetphy commented Jul 26, 2022

Copy link
Copy Markdown
Member Author

Thank you for addressing this issue! FWIW, I'd suggest using tools focused on XSS sanitization such as dompurify.

@jorgectf We are planning to integrate the library you recommended in our next release because accordingly, we need to update every tool with the API. So, this is just a hotfix right now.

@neSpecc

neSpecc commented Jul 26, 2022

Copy link
Copy Markdown
Member

I think, the best soultuion is to support our sanitization config at the pasteConfig.tags configuration:

  static get pasteConfig() {
    return {
      tags: [ 'img[src]' ],  // <-- all attributes except 'src' will be stripped
    };
  }

@neSpecc I tried this solution but in that case, the configuration for sanitisation is as below:

{
    "p": true,
    "h1": true,
    "h2": true,
    "h3": true,
    "h4": true,
    "h5": true,
    "h6": true,
    "img[src]": true,
    "pre": true,
    "b": {},
    "i": {},
    "a": {
        "href": true,
        "target": "_blank",
        "rel": "nofollow"
    },
    "mark": {
        "class": "cdx-marker"
    },
    "code": {
        "class": "inline-code"
    },
    "br": {}
}```
and in that case, if I paste this correct configuration.
`<img src='https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg'/>`
it's not working. the sanitized data comes empty and it pastes as text.

You should not create a config manually, it should be collected from tools. For example, Image tool should change img with img[src] here

@robonetphy

Copy link
Copy Markdown
Member Author

I think, the best soultuion is to support our sanitization config at the pasteConfig.tags configuration:

  static get pasteConfig() {
    return {
      tags: [ 'img[src]' ],  // <-- all attributes except 'src' will be stripped
    };
  }

@neSpecc I tried this solution but in that case, the configuration for sanitisation is as below:

{
    "p": true,
    "h1": true,
    "h2": true,
    "h3": true,
    "h4": true,
    "h5": true,
    "h6": true,
    "img[src]": true,
    "pre": true,
    "b": {},
    "i": {},
    "a": {
        "href": true,
        "target": "_blank",
        "rel": "nofollow"
    },
    "mark": {
        "class": "cdx-marker"
    },
    "code": {
        "class": "inline-code"
    },
    "br": {}
}```
and in that case, if I paste this correct configuration.
`<img src='https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg'/>`
it's not working. the sanitized data comes empty and it pastes as text.

You should not create a config manually, it should be collected from tools. For example, Image tool should change img with img[src] here

Yup, I have done the same things I am just doing console.log inside the Paste module as debugging. So I know it will take updated value from simple-image tool

@robonetphy robonetphy changed the title Temporary Resolutions of XSS Problem Temporary resolutions of XSS problem Aug 3, 2022

@gohabereg gohabereg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to cover it with unit tests

Comment thread src/components/modules/paste.ts Outdated
Comment thread src/components/modules/paste.ts Outdated
Comment thread src/components/modules/paste.ts Outdated
Comment thread src/components/modules/paste.ts Outdated
Comment thread src/components/modules/paste.ts Outdated
Comment thread src/components/modules/paste.ts Outdated
robonetphy and others added 3 commits November 8, 2022 01:58
@robonetphy robonetphy requested a review from neSpecc November 7, 2022 21:48
Comment thread src/components/modules/paste.ts Outdated
Comment thread src/components/modules/paste.ts Outdated
@robonetphy robonetphy requested a review from neSpecc November 11, 2022 18:32
Co-authored-by: Jorge <46056498+jorgectf@users.noreply.github.com>
@neSpecc

neSpecc commented Nov 11, 2022

Copy link
Copy Markdown
Member

add a changelog describing fix and API change please

@neSpecc

neSpecc commented Nov 11, 2022

Copy link
Copy Markdown
Member

The solution still does not work as expected. If a Tool does not specify the sanitizer config, all attributes should be removed. For now, it doesn't work.

I'm digging into it.

@neSpecc

neSpecc commented Nov 11, 2022

Copy link
Copy Markdown
Member

Seems ok for now. Will test it again tomorrow

@robonetphy

Copy link
Copy Markdown
Member Author

hey @neSpecc, Pls check and let me know when to merge.

@neSpecc

neSpecc commented Nov 21, 2022

Copy link
Copy Markdown
Member

@neSpecc neSpecc changed the title Temporary resolutions of XSS problem fix(tools-api): pasteConfig.tags now supports a sanitize config Nov 21, 2022
@neSpecc neSpecc merged commit f659015 into next Nov 21, 2022
@neSpecc neSpecc deleted the fix/xss-problem branch November 21, 2022 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants