-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4602 from C-Hess/fix/xss-youtube-risk
fix(extension-youtube) XSS risk with src tag
- Loading branch information
Showing
4 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Editor } from '@tiptap/core' | ||
import Document from '@tiptap/extension-document' | ||
import Link from '@tiptap/extension-link' | ||
import Paragraph from '@tiptap/extension-paragraph' | ||
import Text from '@tiptap/extension-text' | ||
|
||
/** | ||
* Most link tests should actually exist in the demo/ app folder | ||
*/ | ||
describe('extension-link', () => { | ||
const editorElClass = 'tiptap' | ||
let editor: Editor | null = null | ||
|
||
const createEditorEl = () => { | ||
const editorEl = document.createElement('div') | ||
|
||
editorEl.classList.add(editorElClass) | ||
document.body.appendChild(editorEl) | ||
return editorEl | ||
} | ||
const getEditorEl = () => document.querySelector(`.${editorElClass}`) | ||
|
||
it('does not output src tag for javascript schema', () => { | ||
editor = new Editor({ | ||
element: createEditorEl(), | ||
extensions: [ | ||
Document, | ||
Text, | ||
Paragraph, | ||
Link, | ||
], | ||
content: { | ||
type: 'doc', | ||
content: [ | ||
{ | ||
type: 'paragraph', | ||
content: [ | ||
{ | ||
type: 'text', | ||
text: 'hello world!', | ||
marks: [ | ||
{ | ||
type: 'link', | ||
attrs: { | ||
// We have to disable the eslint rule here because we're trying to purposely test eval urls | ||
// eslint-disable-next-line no-script-url | ||
href: 'javascript:alert(window.origin)', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
// eslint-disable-next-line no-script-url | ||
expect(editor.getHTML()).to.not.include('javascript:alert(window.origin)') | ||
|
||
editor?.destroy() | ||
getEditorEl()?.remove() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Editor } from '@tiptap/core' | ||
import Document from '@tiptap/extension-document' | ||
import Paragraph from '@tiptap/extension-paragraph' | ||
import Text from '@tiptap/extension-text' | ||
import Youtube from '@tiptap/extension-youtube' | ||
|
||
/** | ||
* Most youtube tests should actually exist in the demo/ app folder | ||
*/ | ||
describe('extension-youtube', () => { | ||
const editorElClass = 'tiptap' | ||
let editor: Editor | null = null | ||
|
||
const createEditorEl = () => { | ||
const editorEl = document.createElement('div') | ||
|
||
editorEl.classList.add(editorElClass) | ||
document.body.appendChild(editorEl) | ||
return editorEl | ||
} | ||
const getEditorEl = () => document.querySelector(`.${editorElClass}`) | ||
|
||
const invalidUrls = [ | ||
// We have to disable the eslint rule here because we're trying to purposely test eval urls | ||
// eslint-disable-next-line no-script-url | ||
'javascript:alert(window.origin)//embed/', | ||
'https://youtube.google.com/embed/fdsafsdf', | ||
'https://youtube.com.bad/embed', | ||
] | ||
|
||
invalidUrls.forEach(url => { | ||
it(`does not output html for javascript schema or non-youtube links for url ${url}`, () => { | ||
editor = new Editor({ | ||
element: createEditorEl(), | ||
extensions: [ | ||
Document, | ||
Text, | ||
Paragraph, | ||
Youtube, | ||
], | ||
content: { | ||
type: 'doc', | ||
content: [ | ||
{ | ||
type: 'youtube', | ||
attrs: { | ||
src: url, | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
expect(editor.getHTML()).to.not.include(url) | ||
|
||
editor?.destroy() | ||
getEditorEl()?.remove() | ||
}) | ||
}) | ||
}) |