-
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: render description links #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ export const prerender = true; | |
|
|
||
| import BaseLayout from "../layouts/BaseLayout.astro"; | ||
| import PythonLogo from "../components/PythonLogo.astro"; | ||
| import { formatDate, postUrl, withBase } from "../lib/utils"; | ||
| import { formatDate, postUrl, withBase, renderDescriptionLinks } from "../lib/utils"; | ||
| import { getCollection } from "astro:content"; | ||
|
|
||
| const allPosts = await getCollection("posts"); | ||
|
|
@@ -66,9 +66,7 @@ const authors = new Set(posts.map((p) => p.data.author)); | |
| </div> | ||
|
|
||
| {featured.data.description && ( | ||
| <p class="mt-3 max-w-2xl text-base leading-relaxed text-zinc-600 dark:text-zinc-400 sm:text-lg"> | ||
| {featured.data.description} | ||
| </p> | ||
| <p class="mt-3 max-w-2xl text-base leading-relaxed text-zinc-600 dark:text-zinc-400 sm:text-lg" set:html={renderDescriptionLinks(featured.data.description)} /> | ||
|
||
| )} | ||
| </a> | ||
|
|
||
|
|
@@ -132,7 +130,7 @@ const authors = new Set(posts.map((p) => p.data.author)); | |
| <time datetime={post.data.publishDate.toISOString()}>{formatDate(post.data.publishDate.toISOString())}</time> | ||
| </div> | ||
| {post.data.description && ( | ||
| <p class="mt-2 line-clamp-2 text-sm leading-relaxed text-zinc-500 dark:text-zinc-400">{post.data.description}</p> | ||
| <p class="mt-2 line-clamp-2 text-sm leading-relaxed text-zinc-500 dark:text-zinc-400" set:html={renderDescriptionLinks(post.data.description)} /> | ||
|
||
| )} | ||
| </article> | ||
| ))} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
descriptionprop is rendered viaset:html={renderDescriptionLinks(description)}, which outputs raw HTML built from unescaped description text. BecauserenderDescriptionLinkssimply interpolates regex capture groups into an<a href="...">template, malicious descriptions can inject arbitrary attributes,javascript:URLs, or HTML tags and trigger XSS when the card is viewed or clicked. Use a safe markdown/HTML rendering pipeline that escapes or strips dangerous tags/URL schemes instead of directly injecting the description viaset:html.