Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.8k
update: added html sanitizer for remote rendering#1128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,7 @@ import { resolve, basename } from 'path'; | ||
| import resolvePathname from 'resolve-pathname'; | ||
| import fetch from 'node-fetch'; | ||
| import debug from 'debug'; | ||
| import DOMPurify from 'dompurify'; | ||
| import { AbstractHistory } from '../../src/core/router/history/abstract'; | ||
| import { Compiler } from '../../src/core/render/compiler'; | ||
| import { isAbsolutePath } from '../../src/core/router/util'; | ||
| @@ -13,6 +14,32 @@ function cwd(...args) { | ||
| return resolve(process.cwd(), ...args); | ||
| } | ||
| function isExternal(url) { | ||
| let match = url.match( | ||
| /^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/ | ||
trusktr marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ); | ||
| if ( | ||
| typeof match[1] === 'string' && | ||
| match[1].length > 0 && | ||
| match[1].toLowerCase() !== location.protocol | ||
| ) { | ||
| return true; | ||
| } | ||
| if ( | ||
| typeof match[2] === 'string' && | ||
| match[2].length > 0 && | ||
| match[2].replace( | ||
| new RegExp( | ||
| ':(' + { 'http:': 80, 'https:': 443 }[location.protocol] + ')?$' | ||
| ), | ||
| '' | ||
| ) !== location.host | ||
trusktr marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
anikethsaha marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| function mainTpl(config) { | ||
| let html = `<nav class="app-nav${ | ||
| config.repo ? '' : ' no-badge' | ||
| @@ -60,6 +87,7 @@ export default class Renderer { | ||
| async renderToString(url) { | ||
| this.url = url = this.router.parse(url).path; | ||
| this.isRemoteUrl = isExternal(this.url); | ||
| const { loadSidebar, loadNavbar, coverpage } = this.config; | ||
| const mainFile = this._getPath(url); | ||
| @@ -95,9 +123,8 @@ export default class Renderer { | ||
| this._renderHtml('cover', await this._render(coverFile), 'cover'); | ||
| } | ||
| const html = this.html; | ||
| const html = this.isRemoteUrl ? DOMPurify.sanitize(this.html) : this.html; | ||
anikethsaha marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| this.html = this.template; | ||
| return html; | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.