From 10001111d8c11e0b26f87997ba54d62ab553afdc Mon Sep 17 00:00:00 2001 From: "i.seliverstov" Date: Sun, 18 Oct 2026 22:09:14 +0500 Subject: [PATCH 1/9] feat(tasks): render safe Markdown descriptions --- alfy-bot-frontend/package-lock.json | 122 +++++++++++++++++ alfy-bot-frontend/package.json | 2 + .../src/shared/ui/MarkdownContent.vue | 127 ++++++++++++++++++ .../tests/shared/ui/MarkdownContent.spec.ts | 57 ++++++++ 4 files changed, 308 insertions(+) create mode 100644 alfy-bot-frontend/src/shared/ui/MarkdownContent.vue create mode 100644 alfy-bot-frontend/tests/shared/ui/MarkdownContent.spec.ts diff --git a/alfy-bot-frontend/package-lock.json b/alfy-bot-frontend/package-lock.json index f246f01..707d971 100644 --- a/alfy-bot-frontend/package-lock.json +++ b/alfy-bot-frontend/package-lock.json @@ -16,6 +16,7 @@ "clsx": "^2.1.1", "date-fns": "^4.1.0", "lucide-vue-next": "^0.574.0", + "markdown-it": "^15.0.3", "pinia": "^3.0.4", "reka-ui": "^2.8.2", "tailwind-merge": "^3.5.0", @@ -30,6 +31,7 @@ "devDependencies": { "@antfu/eslint-config": "^7.4.3", "@tailwindcss/vite": "^4.2.0", + "@types/markdown-it": "^14.2.0", "@types/node": "^24.10.1", "@vitejs/plugin-vue": "^6.0.2", "@vue/test-utils": "^2.4.6", @@ -4391,6 +4393,24 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/linkify-it": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz", + "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/markdown-it": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.2.0.tgz", + "integrity": "sha512-NoQ2yGlLWj4wpxMs+TYmRKk3thDrQ97agr7sFqfLsAlvoS8SNQuTrlObhFqG9iugdTtgOE9jpJ6FNM4ZGsa5xQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/linkify-it": "^5", + "@types/mdurl": "^2" + } + }, "node_modules/@types/mdast": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", @@ -4401,6 +4421,13 @@ "@types/unist": "*" } }, + "node_modules/@types/mdurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz", + "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/ms": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", @@ -9304,6 +9331,25 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/linkify-it": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-6.1.0.tgz", + "integrity": "sha512-wJ/TwpSDTLepCrQoYWYIExIKg5Zchex2Nn5yk2mFnB+6PtdkHtyLx742md9csRjjOnGkKIS/RrbY7l8D6gT9Vw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/markdown-it" + } + ], + "license": "MIT", + "dependencies": { + "uc.micro": "^3.0.0" + } + }, "node_modules/local-pkg": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-1.1.2.tgz", @@ -9409,6 +9455,61 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/markdown-it": { + "version": "15.0.3", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-15.0.3.tgz", + "integrity": "sha512-+Az7Ojz3iRGu8KYMvJ6xVhvrxP3eE+vEtJX75Ow88XBpcQNV/0lGX5ZynIIBftREo4DC2jsveAMDaeltmm8QvQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/markdown-it" + } + ], + "license": "MIT", + "dependencies": { + "argparse": "^3.0.3", + "entities": "^8.1.0", + "linkify-it": "^6.1.0", + "mdurl": "^2.1.0", + "punycode.js": "^2.3.1", + "uc.micro": "^3.0.0" + }, + "bin": { + "markdown-it": "bin/markdown-it.mjs" + } + }, + "node_modules/markdown-it/node_modules/argparse": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-3.0.3.tgz", + "integrity": "sha512-Sn98ftV3KfsO8xfLPHG6oT8y+b0yvbrLgZjgPDXsharNY15tTAjqIsIju4S32nl6/iEUNNE4v+yL2Zhm8ooP3w==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "PSF-2.0" + }, + "node_modules/markdown-it/node_modules/entities": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-8.1.0.tgz", + "integrity": "sha512-kxL7msIffSuh9aaFAMD7rxAIuTRMAHMeBtgHW2yUdWw732ZNh4MehkF2gdjvtdmikkaIP9bFDDJOPlsvm7avrA==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/markdown-table": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/markdown-table/-/markdown-table-3.0.4.tgz", @@ -9674,6 +9775,12 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/mdurl": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.1.0.tgz", + "integrity": "sha512-1+HBaOx0zi/dQWht8rNv9MYf9qqpqL/kxI0hXImU6Y547zM6Sni8BQibt7ifgMcYtQg41ao3Ivd6cnSM86inpg==", + "license": "MIT" + }, "node_modules/micromark": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.2.tgz", @@ -10965,6 +11072,15 @@ "node": ">=6" } }, + "node_modules/punycode.js": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", + "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/quansync": { "version": "0.2.11", "resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.11.tgz", @@ -12517,6 +12633,12 @@ "node": ">=14.17" } }, + "node_modules/uc.micro": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-3.0.0.tgz", + "integrity": "sha512-U3PppEkleoTnIfi8BozMx3yju3qc/L6SwqWo2Sw+54PX+PX0q9I+r1Um5HCmqD7n9VDX5/v3vQH/AjA6deDdtw==", + "license": "MIT" + }, "node_modules/ufo": { "version": "1.6.3", "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.3.tgz", diff --git a/alfy-bot-frontend/package.json b/alfy-bot-frontend/package.json index e290a7f..65d5b2d 100644 --- a/alfy-bot-frontend/package.json +++ b/alfy-bot-frontend/package.json @@ -21,6 +21,7 @@ "clsx": "^2.1.1", "date-fns": "^4.1.0", "lucide-vue-next": "^0.574.0", + "markdown-it": "^15.0.3", "pinia": "^3.0.4", "reka-ui": "^2.8.2", "tailwind-merge": "^3.5.0", @@ -35,6 +36,7 @@ "devDependencies": { "@antfu/eslint-config": "^7.4.3", "@tailwindcss/vite": "^4.2.0", + "@types/markdown-it": "^14.2.0", "@types/node": "^24.10.1", "@vitejs/plugin-vue": "^6.0.2", "@vue/test-utils": "^2.4.6", diff --git a/alfy-bot-frontend/src/shared/ui/MarkdownContent.vue b/alfy-bot-frontend/src/shared/ui/MarkdownContent.vue new file mode 100644 index 0000000..5d43cf6 --- /dev/null +++ b/alfy-bot-frontend/src/shared/ui/MarkdownContent.vue @@ -0,0 +1,127 @@ + + + + + diff --git a/alfy-bot-frontend/tests/shared/ui/MarkdownContent.spec.ts b/alfy-bot-frontend/tests/shared/ui/MarkdownContent.spec.ts new file mode 100644 index 0000000..d8bc684 --- /dev/null +++ b/alfy-bot-frontend/tests/shared/ui/MarkdownContent.spec.ts @@ -0,0 +1,57 @@ +import { mount } from '@vue/test-utils' +import { describe, expect, it } from 'vitest' +import MarkdownContent from '@/shared/ui/MarkdownContent.vue' + +function render(content: string) { + return mount(MarkdownContent, { props: { content } }) +} + +describe('markdownContent', () => { + it('renders named links and bare URLs with safe external navigation', () => { + const wrapper = render('[Схема](https://github.com/example/schema/pull/5) и https://example.com/client') + const links = wrapper.findAll('a') + expect(links).toHaveLength(2) + expect(links[0]!.text()).toBe('Схема') + expect(links[0]!.attributes('href')).toBe('https://github.com/example/schema/pull/5') + expect(links[1]!.attributes('href')).toBe('https://example.com/client') + for (const link of links) { + expect(link.attributes('target')).toBe('_blank') + expect(link.attributes('rel')).toBe('noopener noreferrer') + } + }) + + it.each(['javascript:alert(1)', 'vbscript:alert(1)', 'data:text/html,test', 'file:///etc/passwd'])('does not create a link for %s', (url) => { + expect(render(`[Опасная ссылка](${url})`).find('a').exists()).toBe(false) + }) + + it('escapes HTML and encoded unsafe schemes', () => { + const wrapper = render('\n[Ссылка](javascript:alert(1))') + expect(wrapper.find('script').exists()).toBe(false) + expect(wrapper.find('img').exists()).toBe(false) + expect(wrapper.findAll('a').every(link => link.attributes('href')?.startsWith('https://'))).toBe(true) + expect(render('[Ссылка](javascript:alert(1))').find('a').exists()).toBe(false) + expect(wrapper.text()).toContain('') + }) + + it('preserves line breaks and renders basic formatting, lists and code', () => { + const wrapper = render('Первая строка\nВторая **важная** строка\n\n- Один\n- Два\n\n` + +