Fix security related problems (#1522)

* Remove unnecessary capture group from regex

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

* Rename component to make name more expressive

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

* Remove redundant expression

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

* Filter vbscript links

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

* Remove superfluous parameter

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

* Check if handler is set

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

* Fix doc

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2021-10-01 22:51:57 +02:00 committed by GitHub
parent 0e512531a0
commit 87d6285da5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 11 deletions

View file

@ -15,9 +15,12 @@ interface RouteParameters {
id: string
}
export const Redirector: React.FC = () => {
/**
* Redirects the user to the editor if the link is a root level direct link to a version 1 note.
*/
export const NoteDirectLinkRedirector: React.FC = () => {
const { id } = useParams<RouteParameters>()
const [error, setError] = useState<boolean | null>(null)
const [error, setError] = useState<boolean | undefined>(undefined)
useEffect(() => {
getNote(id)
@ -25,9 +28,9 @@ export const Redirector: React.FC = () => {
.catch(() => setError(true))
}, [id])
if (error) {
if (error === true) {
return <NotFoundErrorScreen />
} else if (!error && error != null) {
} else if (error === false) {
return <Redirect to={`/n/${id}`} />
} else {
return <span>Loading</span>

View file

@ -12,7 +12,7 @@ import { Logger } from '../../../../utils/logger'
type highlightJsImport = typeof import('../../../common/hljs/hljs')
const log = new Logger('Autocompletion > CodeBlock')
const wordRegExp = /^```((\w|-|_|\+)*)$/
const wordRegExp = /^```((?:\w|-|_|\+)*)$/
let allSupportedLanguages: string[] = []
/**

View file

@ -8,7 +8,7 @@ import { Editor, Hint, Hints, Pos } from 'codemirror'
import { validAlertLevels } from '../../../markdown-renderer/markdown-it-plugins/alert-container'
import { findWordAtCursor, Hinter } from './index'
const wordRegExp = /^:::((\w|-|_|\+)*)$/
const wordRegExp = /^:::((?:\w|-|_|\+)*)$/
const spoilerSuggestion: Hint = {
text: ':::spoiler Toggle label\nToggled content\n::: \n',
displayText: 'spoiler'

View file

@ -36,7 +36,7 @@ export class LinkReplacer extends ComponentReplacer {
const url = node.attribs.href.trim()
// eslint-disable-next-line no-script-url
if (url.startsWith('data:') || url.startsWith('javascript:')) {
if (url.startsWith('data:') || url.startsWith('javascript:') || url.startsWith('vbscript:')) {
return <span>{node.attribs.href}</span>
}

View file

@ -96,7 +96,7 @@ export const buildTransformer = (
return convertNodeToReactElement(node, index)
}
const nativeRenderer: NativeRenderer = () => renderNativeNode(node, key, transform)
const subNodeTransform: SubNodeTransform = (subNode, subKey) => transform(subNode, subKey, transform)
const subNodeTransform: SubNodeTransform = (subNode, subKey) => transform(subNode, subKey)
const key = calculateKeyFromLineMarker(node, lineKeys) ?? (-index).toString()
const tryReplacement = findNodeReplacement(node, allReplacers, subNodeTransform, nativeRenderer)

View file

@ -121,6 +121,9 @@ export abstract class WindowPostMessageCommunicator<
protected handleEvent(event: MessageEvent<PostMessage<RECEIVE_TYPE>>): boolean | undefined {
const data = event.data
if (!(data.type in this.handlers)) {
return true
}
const handler = this.handlers[data.type]
if (!handler) {
return true