Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
fix(web): load managed attachment images on instances served over http
johnnyjoyghfa9098167159
diff --git a/web/package.json b/web/package.jsonindex 64d1d3e21..1ba08cf71 100644--- a/web/package.json+++ b/web/package.json@@ -25,7 +25,7 @@"@tailwindcss/vite": "^4.2.4","@tanstack/react-query": "^5.100.9","@tanstack/react-query-devtools": "^5.100.9",- "@usememos/editor": "26.10.5",+ "@usememos/editor": "26.10.7","class-variance-authority": "^0.7.1","clsx": "^2.1.1","copy-to-clipboard": "^4.0.2",diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yamlindex 3878397dd..0c0833e85 100644--- a/web/pnpm-lock.yaml+++ b/web/pnpm-lock.yaml@@ -36,8 +36,8 @@ importers:specifier: ^5.100.9'@usememos/editor':- specifier: 26.10.5+ specifier: 26.10.7class-variance-authority:specifier: ^0.7.1version: 0.7.1@@ -1135,8 +1135,8 @@ packages:'@upsetjs/[email protected]':resolution: {integrity: sha512-WbBhLrooyePuQ1VZxrJjtLvTc4NVfpOyKx0sKqioq9bX1C1m7Jgykkn8gLrtwumBioXIqam8DLxp88Adbue6Hw==}- '@usememos/[email protected]':- resolution: {integrity: sha512-bqb3NauLyG9Z4YNusgHQI3IOiksR42aLpZCcE0ltDZEYq6j/fuUO2AKEROiYIu5T9b0sWYNQwy3yjHltAGlhmA==}+ '@usememos/[email protected]':+ resolution: {integrity: sha512-PNnOLcVFPLn7yRmhgMmW/JemrOZlp6wvoDMQbuZ3r+Tz66Hz73O/LOKfSqyF3+WZm9X/cXBOV3O8bcTSLyfXUw==}peerDependencies:react: '>=18'react-dom: '>=18'@@ -3262,7 +3262,7 @@ snapshots:d3-selection: 3.0.0d3-transition: 3.0.1([email protected])optionalDependencies:react: 19.2.6react-dom: 19.2.6([email protected])diff --git a/web/src/components/MemoEditor/Editor/editor.css b/web/src/components/MemoEditor/Editor/editor.cssindex 5d3ee02fb..20042cf73 100644--- a/web/src/components/MemoEditor/Editor/editor.css+++ b/web/src/components/MemoEditor/Editor/editor.css@@ -8,10 +8,17 @@max-height: 50vh;overflow-y: auto;}+ /* Focus mode fills the frame, and so does the editable root: a click anywhere+ below the text lands in the editor, which puts the caret at the end. */&[data-focus-mode] .memo-editor-scroller {+ display: flex;+ flex-direction: column;height: 100%;max-height: none;}+ &[data-focus-mode] .memo-editor-root {+ flex: 1 0 auto;+ }& .memo-editor-root {caret-color: var(--foreground);outline: none;diff --git a/web/src/lib/memo-markdown.ts b/web/src/lib/memo-markdown.tsindex f305480a2..82ca6a1c5 100644--- a/web/src/lib/memo-markdown.ts+++ b/web/src/lib/memo-markdown.ts@@ -228,16 +228,16 @@ export const memoExtensions = (options: MemoExtensionOptions = {}): Extension[]const isAllowedImageSource = (src: string): boolean => !/^[a-z][a-z0-9+.-]*:/i.test(src) || /^https:/i.test(src);/**- * memos' URL policy: managed attachment images resolve to their served URL and load- * from relative or https URLs only; links also allow `sms:`, which hands off to- * another app, beyond the editor's defaults.+ * memos' URL policy: images the memo names load from relative or https URLs only, and+ * managed attachment images then resolve to their served URL, which is the instance's+ * own origin and may be plain http. Links also allow `sms:`, which hands off to another+ * app, beyond the editor's defaults.*/export const memoResolveUrl =(attachments: readonly Attachment[] = []): ResolveUrl =>(url, kind) => {if (kind === "image") {- const resolved = resolveManagedAttachmentImageSource(url, [...attachments]) ?? url;- return isAllowedImageSource(resolved) ? resolved : null;+ return isAllowedImageSource(url) ? (resolveManagedAttachmentImageSource(url, [...attachments]) ?? url) : null;}return /^sms:/i.test(url.trim()) ? url.trim() : defaultResolveUrl(url, kind);};diff --git a/web/tests/memo-content-security.test.ts b/web/tests/memo-content-security.test.tsindex 834a0e48e..a6e726b46 100644--- a/web/tests/memo-content-security.test.ts+++ b/web/tests/memo-content-security.test.ts@@ -1,6 +1,9 @@+import { create } from "@bufbuild/protobuf";import { describe, expect, it } from "vitest";import { isTrustedIframeSrc } from "@/lib/html-sanitize-schema";+import { memoResolveUrl } from "@/lib/memo-markdown";import { renderSanitizedHtml } from "@/lib/sanitized-html";+import { AttachmentSchema } from "@/types/proto/api/attachment_service_pb";const renderHtml = (source: string): string => {const element = document.createElement("div");@@ -70,3 +73,19 @@ describe("trusted iframe providers", () => {expect(isTrustedIframeSrc("https://evil.example/embed/abc123")).toBe(false);});});++describe("image URL policy", () => {+ const resolve = memoResolveUrl([create(AttachmentSchema, { name: "attachments/photo", filename: "photo.png", type: "image/png" })]);++ it("loads images the memo names from relative or https URLs only", () => {+ expect(resolve("/assets/a.png", "image")).toBe("/assets/a.png");+ expect(resolve("https://img.example/a.png", "image")).toBe("https://img.example/a.png");+ expect(resolve("http://tracker.example/a.png", "image")).toBeNull();+ expect(resolve("javascript:alert(1)", "image")).toBeNull();+ });++ it("resolves a managed attachment image to the instance's own URL, even over plain http", () => {+ expect(window.location.protocol).toBe("http:");+ expect(resolve("/file/attachments/photo", "image")).toBe(`${window.location.origin}/file/attachments/photo/photo.png`);+ });+});