#263 PostEmbed の安全性強化(#130)

Merged
みてるぞ merged 3 commits from feature/130 into main 5 hours ago
  1. +23
    -5
      frontend/src/components/PostEmbed.tsx

+ 23
- 5
frontend/src/components/PostEmbed.tsx View File

@@ -18,17 +18,35 @@ export default (({ post }: Props) => {
{
case 'nicovideo.jp':
{
const [videoId] = url.pathname.match (/(?<=\/watch\/)[a-zA-Z0-9]+?(?=\/|$)/)!
const mVideoId = url.pathname.match (/(?<=\/watch\/)[a-zA-Z0-9]+?(?=\/|$)/)
if (!(mVideoId))
break

const [videoId] = mVideoId

return <NicoViewer id={videoId} width={640} height={360}/>
}

case 'twitter.com':
case 'x.com':
const [userId] = url.pathname.match (/(?<=\/)[^\/]+?(?=\/|$|\?)/)!
const [statusId] = url.pathname.match (/(?<=\/status\/)\d+?(?=\/|$|\?)/)!
return <TwitterEmbed userId={userId} statusId={statusId}/>
{
const mUserId = url.pathname.match (/(?<=\/)[^\/]+?(?=\/|$|\?)/)
const mStatusId = url.pathname.match (/(?<=\/status\/)\d+?(?=\/|$|\?)/)
if (!(mUserId) || !(mStatusId))
break

const [userId] = mUserId
const [statusId] = mStatusId

return <TwitterEmbed userId={userId} statusId={statusId}/>
}

case 'youtube.com':
{
const videoId = url.searchParams.get ('v')!
const videoId = url.searchParams.get ('v')
if (!(videoId))
break

return (
<YoutubeEmbed videoId={videoId} opts={{ playerVars: {
playsinline: 1,


Loading…
Cancel
Save