Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(youtube): Incomplete URL substring sanitization

tzhangchifd9ed2862f1d
diff --git a/libs/components/editor-blocks/src/blocks/youtube/index.ts b/libs/components/editor-blocks/src/blocks/youtube/index.ts
index 26e4117961..42f22bcda4 100644
--- a/libs/components/editor-blocks/src/blocks/youtube/index.ts
+++ b/libs/components/editor-blocks/src/blocks/youtube/index.ts
@@ -1,9 +1,9 @@
+import { Protocol } from '@toeverything/datasource/db-service';
import {
AsyncBlock,
BaseView,
SelectBlock,
} from '@toeverything/framework/virgo';
-import { Protocol } from '@toeverything/datasource/db-service';
import { YoutubeView } from './YoutubeView';
export class YoutubeBlock extends BaseView {
@@ -19,9 +19,10 @@ export class YoutubeBlock extends BaseView {
const tag_name = el.tagName;
if (tag_name === 'A' && el.parentElement?.childElementCount === 1) {
const href = el.getAttribute('href');
- const allowedHosts = ['.youtube.com'];
+ const allowedHosts = ['www.youtu.be', 'www.youtube.com'];
+ const host = new URL(href).host;
- if (allowedHosts.includes(href)) {
+ if (allowedHosts.includes(host)) {
return [
{
type: this.type,
diff --git a/libs/components/editor-blocks/src/components/source-view/format-url/youtube.ts b/libs/components/editor-blocks/src/components/source-view/format-url/youtube.ts
index 202f0dc968..56f165a515 100644
--- a/libs/components/editor-blocks/src/components/source-view/format-url/youtube.ts
+++ b/libs/components/editor-blocks/src/components/source-view/format-url/youtube.ts
@@ -1,6 +1,7 @@
export const isYoutubeUrl = (url?: string): boolean => {
- const allowedHosts = ['youtu.be', 'youtube.com'];
- return allowedHosts.includes(url);
+ const allowedHosts = ['www.youtu.be', 'www.youtube.com'];
+ const host = new URL(url).host;
+ return allowedHosts.includes(host);
};
const _regexp = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#&?]*).*/;