Skip to content

Commit

Permalink
fix: validate docs links (usebruno#3122)
Browse files Browse the repository at this point in the history
* fix: validate docs links

* fix: only allow external urls, ignore filesystem paths

* fix: updates

* chore: revert spacing
  • Loading branch information
lohxt1 authored Sep 18, 2024
1 parent 938e056 commit 07baa63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/bruno-app/src/components/MarkDown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;
}
Expand Down
11 changes: 9 additions & 2 deletions packages/bruno-electron/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
});

Expand Down

0 comments on commit 07baa63

Please sign in to comment.