Skip to content

Commit bf7b2f4

Browse files
ChengaDevclaude
andcommitted
Fix YouTube URL security, improve landing page spacing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f0b12f1 commit bf7b2f4

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/components/YouTubePage.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ function saveToHistory(id: string) {
2121
localStorage.setItem(HISTORY_KEY, JSON.stringify(updated))
2222
}
2323

24+
const VIDEO_ID_RE = /^[a-zA-Z0-9_-]{11}$/
25+
2426
const parseVideoId = (input: string): string | null => {
2527
const trimmed = input.trim()
28+
const validate = (id: string | null) => (id && VIDEO_ID_RE.test(id) ? id : null)
2629
try {
2730
const url = new URL(trimmed)
2831
if (url.hostname.includes('youtube.com')) {
29-
return url.searchParams.get('v')
32+
return validate(url.searchParams.get('v'))
3033
}
3134
if (url.hostname === 'youtu.be') {
32-
const id = url.pathname.slice(1).split('?')[0]
33-
return id || null
35+
return validate(url.pathname.slice(1).split('?')[0])
3436
}
3537
} catch {
36-
if (/^[a-zA-Z0-9_-]{11}$/.test(trimmed)) return trimmed
38+
return validate(trimmed)
3739
}
3840
return null
3941
}
@@ -198,7 +200,8 @@ const LandingWrapper = styled.div`
198200
display: flex;
199201
flex-direction: column;
200202
align-items: center;
201-
padding: 2rem 1.5rem 3rem;
203+
min-height: calc(65vh - 80px);
204+
padding: 6rem 1.5rem 9rem;
202205
203206
@media (max-width: 768px) and (orientation: portrait) {
204207
padding-top: 1.5rem;

0 commit comments

Comments
 (0)