fix: validate docs links (#3122)

* fix: validate docs links

* fix: only allow external urls, ignore filesystem paths

* fix: updates

* chore: revert spacing
This commit is contained in:
lohit 2024-09-18 17:02:39 +05:30 committed by GitHub
parent 938e0560a2
commit 07baa63e9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import MarkdownIt from 'markdown-it';
import * as MarkdownItReplaceLink from 'markdown-it-replace-link';
import StyledWrapper from './StyledWrapper';
import React from 'react';
import { isValidUrl } from 'utils/url/index';
const Markdown = ({ collectionPath, onDoubleClick, content }) => {
const markdownItOptions = {
@ -15,7 +16,7 @@ const Markdown = ({ collectionPath, onDoubleClick, content }) => {
if (target.tagName === 'A') {
event.preventDefault();
const href = target.getAttribute('href');
if (href) {
if (href && isValidUrl(href)) {
window.open(href, '_blank');
return;
}

View File

@ -129,8 +129,15 @@ app.on('ready', async () => {
}
});
mainWindow.webContents.setWindowOpenHandler((details) => {
require('electron').shell.openExternal(details.url);
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
try {
const { protocol } = new URL(url);
if (['https:', 'http:'].includes(protocol)) {
require('electron').shell.openExternal(url);
}
} catch (e) {
console.error(e);
}
return { action: 'deny' };
});