mirror of
https://github.com/zadam/trilium.git
synced 2025-10-19 22:58:52 +02:00
refactor(commons): deduplicate allowed protocols
This commit is contained in:
parent
2fca995725
commit
bebd3d430b
@ -3,16 +3,7 @@ import linkContextMenuService from "../menus/link_context_menu.js";
|
|||||||
import appContext, { type NoteCommandData } from "../components/app_context.js";
|
import appContext, { type NoteCommandData } from "../components/app_context.js";
|
||||||
import froca from "./froca.js";
|
import froca from "./froca.js";
|
||||||
import utils from "./utils.js";
|
import utils from "./utils.js";
|
||||||
|
import { ALLOWED_PROTOCOLS } from "@triliumnext/commons";
|
||||||
// Be consistent with `allowedSchemes` in `src\services\html_sanitizer.ts`
|
|
||||||
// TODO: Deduplicate with server once we can.
|
|
||||||
export const ALLOWED_PROTOCOLS = [
|
|
||||||
'http', 'https', 'ftp', 'ftps', 'mailto', 'data', 'evernote', 'file', 'facetime', 'gemini', 'git',
|
|
||||||
'gopher', 'imap', 'irc', 'irc6', 'jabber', 'jar', 'lastfm', 'ldap', 'ldaps', 'magnet', 'message',
|
|
||||||
'mumble', 'nfs', 'onenote', 'pop', 'rmi', 's3', 'sftp', 'skype', 'sms', 'spotify', 'steam', 'svn', 'udp',
|
|
||||||
'view-source', 'vlc', 'vnc', 'ws', 'wss', 'xmpp', 'jdbc', 'slack', 'tel', 'smb', 'zotero', 'geo',
|
|
||||||
'mid'
|
|
||||||
];
|
|
||||||
|
|
||||||
function getNotePathFromUrl(url: string) {
|
function getNotePathFromUrl(url: string) {
|
||||||
const notePathMatch = /#(root[A-Za-z0-9_/]*)$/.exec(url);
|
const notePathMatch = /#(root[A-Za-z0-9_/]*)$/.exec(url);
|
||||||
|
@ -1,17 +1,7 @@
|
|||||||
import sanitizeHtml from "sanitize-html";
|
import sanitizeHtml from "sanitize-html";
|
||||||
import { sanitizeUrl } from "@braintree/sanitize-url";
|
import { sanitizeUrl } from "@braintree/sanitize-url";
|
||||||
import optionService from "./options.js";
|
import optionService from "./options.js";
|
||||||
import { SANITIZER_DEFAULT_ALLOWED_TAGS } from "@triliumnext/commons";
|
import { ALLOWED_PROTOCOLS, SANITIZER_DEFAULT_ALLOWED_TAGS } from "@triliumnext/commons";
|
||||||
|
|
||||||
// Be consistent with `ALLOWED_PROTOCOLS` in `src\public\app\services\link.js`
|
|
||||||
// TODO: Deduplicate with client once we can.
|
|
||||||
export const ALLOWED_PROTOCOLS = [
|
|
||||||
'http', 'https', 'ftp', 'ftps', 'mailto', 'data', 'evernote', 'file', 'facetime', 'gemini', 'git',
|
|
||||||
'gopher', 'imap', 'irc', 'irc6', 'jabber', 'jar', 'lastfm', 'ldap', 'ldaps', 'magnet', 'message',
|
|
||||||
'mumble', 'nfs', 'onenote', 'pop', 'rmi', 's3', 'sftp', 'skype', 'sms', 'spotify', 'steam', 'svn', 'udp',
|
|
||||||
'view-source', 'vlc', 'vnc', 'ws', 'wss', 'xmpp', 'jdbc', 'slack', 'tel', 'smb', 'zotero', 'geo',
|
|
||||||
'mid'
|
|
||||||
];
|
|
||||||
|
|
||||||
// intended mainly as protection against XSS via import
|
// intended mainly as protection against XSS via import
|
||||||
// secondarily, it (partly) protects against "CSS takeover"
|
// secondarily, it (partly) protects against "CSS takeover"
|
||||||
|
@ -1,98 +1,22 @@
|
|||||||
// Default list of allowed HTML tags
|
// Default list of allowed HTML tags
|
||||||
export const SANITIZER_DEFAULT_ALLOWED_TAGS = [
|
export const SANITIZER_DEFAULT_ALLOWED_TAGS = [
|
||||||
"h1",
|
"h1", "h2", "h3", "h4", "h5", "h6", "blockquote", "p", "a", "ul", "ol", "li", "b", "i", "strong", "em",
|
||||||
"h2",
|
"strike", "s", "del", "abbr", "code", "hr", "br", "div", "table", "thead", "caption", "tbody", "tfoot",
|
||||||
"h3",
|
"tr", "th", "td", "pre", "section", "img", "figure", "figcaption", "span", "label", "input", "details",
|
||||||
"h4",
|
"summary", "address", "aside", "footer", "header", "hgroup", "main", "nav", "dl", "dt", "menu", "bdi",
|
||||||
"h5",
|
"bdo", "dfn", "kbd", "mark", "q", "time", "var", "wbr", "area", "map", "track", "video", "audio", "picture",
|
||||||
"h6",
|
"del", "ins",
|
||||||
"blockquote",
|
// for ENEX import
|
||||||
"p",
|
"en-media",
|
||||||
"a",
|
|
||||||
"ul",
|
|
||||||
"ol",
|
|
||||||
"li",
|
|
||||||
"b",
|
|
||||||
"i",
|
|
||||||
"strong",
|
|
||||||
"em",
|
|
||||||
"strike",
|
|
||||||
"s",
|
|
||||||
"del",
|
|
||||||
"abbr",
|
|
||||||
"code",
|
|
||||||
"hr",
|
|
||||||
"br",
|
|
||||||
"div",
|
|
||||||
"table",
|
|
||||||
"thead",
|
|
||||||
"caption",
|
|
||||||
"tbody",
|
|
||||||
"tfoot",
|
|
||||||
"tr",
|
|
||||||
"th",
|
|
||||||
"td",
|
|
||||||
"pre",
|
|
||||||
"section",
|
|
||||||
"img",
|
|
||||||
"figure",
|
|
||||||
"figcaption",
|
|
||||||
"span",
|
|
||||||
"label",
|
|
||||||
"input",
|
|
||||||
"details",
|
|
||||||
"summary",
|
|
||||||
"address",
|
|
||||||
"aside",
|
|
||||||
"footer",
|
|
||||||
"header",
|
|
||||||
"hgroup",
|
|
||||||
"main",
|
|
||||||
"nav",
|
|
||||||
"dl",
|
|
||||||
"dt",
|
|
||||||
"menu",
|
|
||||||
"bdi",
|
|
||||||
"bdo",
|
|
||||||
"dfn",
|
|
||||||
"kbd",
|
|
||||||
"mark",
|
|
||||||
"q",
|
|
||||||
"time",
|
|
||||||
"var",
|
|
||||||
"wbr",
|
|
||||||
"area",
|
|
||||||
"map",
|
|
||||||
"track",
|
|
||||||
"video",
|
|
||||||
"audio",
|
|
||||||
"picture",
|
|
||||||
"del",
|
|
||||||
"ins",
|
|
||||||
"en-media", // for ENEX import
|
|
||||||
// Additional tags (https://github.com/TriliumNext/Trilium/issues/567)
|
// Additional tags (https://github.com/TriliumNext/Trilium/issues/567)
|
||||||
"acronym",
|
"acronym", "article", "big", "button", "cite", "col", "colgroup", "data", "dd", "fieldset", "form", "legend",
|
||||||
"article",
|
"meter", "noscript", "option", "progress", "rp", "samp", "small", "sub", "sup", "template", "textarea", "tt"
|
||||||
"big",
|
|
||||||
"button",
|
|
||||||
"cite",
|
|
||||||
"col",
|
|
||||||
"colgroup",
|
|
||||||
"data",
|
|
||||||
"dd",
|
|
||||||
"fieldset",
|
|
||||||
"form",
|
|
||||||
"legend",
|
|
||||||
"meter",
|
|
||||||
"noscript",
|
|
||||||
"option",
|
|
||||||
"progress",
|
|
||||||
"rp",
|
|
||||||
"samp",
|
|
||||||
"small",
|
|
||||||
"sub",
|
|
||||||
"sup",
|
|
||||||
"template",
|
|
||||||
"textarea",
|
|
||||||
"tt"
|
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
export const ALLOWED_PROTOCOLS = [
|
||||||
|
'http', 'https', 'ftp', 'ftps', 'mailto', 'data', 'evernote', 'file', 'facetime', 'gemini', 'git',
|
||||||
|
'gopher', 'imap', 'irc', 'irc6', 'jabber', 'jar', 'lastfm', 'ldap', 'ldaps', 'magnet', 'message',
|
||||||
|
'mumble', 'nfs', 'onenote', 'pop', 'rmi', 's3', 'sftp', 'skype', 'sms', 'spotify', 'steam', 'svn', 'udp',
|
||||||
|
'view-source', 'vlc', 'vnc', 'ws', 'wss', 'xmpp', 'jdbc', 'slack', 'tel', 'smb', 'zotero', 'geo',
|
||||||
|
'mid'
|
||||||
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user