File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { useEffect, useState } from "react";
1515import Image from "next/image" ;
1616import { AdminGuard } from "@/app/admin/events/AdminGuard" ;
1717import type { SharedLinkView } from "@/app/feed/types" ;
18+ import { sanitizeExternalUrl } from "@/lib/url-safety" ;
1819import { approveLink , listPendingLinks , rejectLink } from "./lib" ;
1920
2021export default function AdminCommunityPage ( ) {
@@ -164,15 +165,30 @@ function AdminCommunityInner() {
164165 { link . host }
165166 </ span >
166167 </ div >
167- < a
168- href = { link . url }
169- target = "_blank"
170- rel = "noopener noreferrer"
171- className = "block mt-2 font-semibold text-base hover:underline truncate"
172- title = { link . ogTitle ?? link . url }
173- >
174- { link . ogTitle ?? link . url }
175- </ a >
168+ { ( ( ) => {
169+ // defense-in-depth:后端 UrlNormalizer 已拒非 http/https,
170+ // 前端仍用 sanitizeExternalUrl 兜底过滤 javascript:/data: 协议。
171+ const safe = sanitizeExternalUrl ( link . url ) ;
172+ const title = link . ogTitle ?? link . url ;
173+ return safe ? (
174+ < a
175+ href = { safe }
176+ target = "_blank"
177+ rel = "noopener noreferrer"
178+ className = "block mt-2 font-semibold text-base hover:underline truncate"
179+ title = { title }
180+ >
181+ { title }
182+ </ a >
183+ ) : (
184+ < span
185+ className = "block mt-2 font-semibold text-base text-neutral-400 truncate"
186+ title = "链接协议不安全,已禁用点击"
187+ >
188+ { title } ⚠
189+ </ span >
190+ ) ;
191+ } ) ( ) }
176192 { link . ogDescription && (
177193 < p className = "mt-1 text-sm text-neutral-600 dark:text-neutral-300 line-clamp-2" >
178194 { link . ogDescription }
You can’t perform that action at this time.
0 commit comments