import { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import Link from 'next/link'; import { useHints } from '../contexts/HintContext'; export default function Profile() { const [user, setUser] = useState<{username: string, isAdmin: boolean} | null>(null); const [profileImage, setProfileImage] = useState(null); const [uploadStatus, setUploadStatus] = useState(''); const [name, setName] = useState(''); const [email, setEmail] = useState(''); const router = useRouter(); const { hintsVisible } = useHints(); useEffect(() => { // Check if user is logged in const userData = localStorage.getItem('user'); if (userData) { setUser(JSON.parse(userData)); } else { router.push('/login'); } }, [router]); const handleImageUpload = () => { if (!profileImage) { setUploadStatus('Please select a file first.'); return; } // Insecure File Upload Vulnerability - No proper validation const fileName = profileImage.name.toLowerCase(); // Simulate file upload with intentional vulnerabilities if (fileName.includes('flag') || fileName.includes('admin')) { setUploadStatus(`FLAG{INSECURE_UPLOAD} - File "${profileImage.name}" uploaded successfully! This demonstrates insecure file upload vulnerability.`); } else if (fileName.endsWith('.php') || fileName.endsWith('.jsp') || fileName.endsWith('.asp')) { setUploadStatus(`Warning: Executable file "${profileImage.name}" uploaded! This could be dangerous. FLAG{FILE_EXECUTION_RISK}`); } else if (fileName.endsWith('.sh') || fileName.endsWith('.bat') || fileName.endsWith('.exe')) { setUploadStatus(`Script file "${profileImage.name}" uploaded successfully. Potential security risk detected.`); } else { setUploadStatus(`Profile image "${profileImage.name}" uploaded successfully.`); } }; const handleLogout = () => { localStorage.removeItem('user'); router.push('/login'); }; if (!user) { return (
◐

Please log in to access your profile.

); } return (
{/* Header */}
{user.isAdmin ? '◆' : '◐'}

Welcome, {user.username}

{user.isAdmin ? 'Administrator Account' : 'User Account'}

{/* Profile Information */}

Profile Information

setName(e.target.value)} placeholder="Enter your display name" className="input-field" />
setEmail(e.target.value)} placeholder="Enter your email" className="input-field" />
{/* Profile Image Upload - VULNERABLE */}

Profile Image

{ setProfileImage(e.target.files?.[0] || null); setUploadStatus(''); }} className={`w-full p-3 bg-hacksmith-gray border border-gray-600 rounded-lg text-gray-300 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:bg-hacksmith-orange file:text-black file:font-semibold ${hintsVisible ? 'border-red-500/30' : ''}`} />

{hintsVisible ? "Supported: JPG, PNG, GIF (but validation is weak...)" : "Upload your profile picture" }

{hintsVisible && (
⚠ File validation insufficient
)}
{profileImage && (

Selected File:

Name: {profileImage.name}
Size: {(profileImage.size / 1024).toFixed(2)} KB
Type: {profileImage.type || 'Unknown'}
)} {uploadStatus && (
{uploadStatus}
)}
{/* Vulnerability Info */} {hintsVisible && (

◐ File Upload Vulnerability

This upload system is intentionally vulnerable:

  • No proper file type validation
  • No file content inspection
  • Weak filename filtering
  • No size restrictions

Try uploading files with names like "flag.txt", "admin.php", or "script.sh"

)} {/* Account Actions */}

Account Actions

{/* Back to Home */}
← Back to Home
); }