import Link from 'next/link'; import { useState, useEffect, useRef } from 'react'; import { useHints } from '../contexts/HintContext'; import { useNotifications } from '../contexts/NotificationContext'; export default function Home() { const [search, setSearch] = useState(''); const [searchResults, setSearchResults] = useState(''); const [xssTriggered, setXssTriggered] = useState(false); const { hintsVisible } = useHints(); const { showFlagNotification } = useNotifications(); const searchResultsRef = useRef(null); const products = [ { id: 1, name: 'Professional Hammer', price: 89, image: '/assets/hammer.png', description: 'Heavy-duty forging hammer perfect for metalworking and blacksmithing projects.' }, { id: 2, name: 'Steel Anvil', price: 299, image: '/assets/anvil.png', description: 'Solid steel anvil for precise metalworking. Essential tool for any blacksmith.' }, { id: 3, name: 'Heat-Resistant Gloves', price: 45, image: '/assets/gloves.png', description: 'Premium heat-resistant gloves for safe handling of hot materials and tools.' }, { id: 4, name: 'Forging Tongs', price: 65, image: '/assets/tongs.png', description: 'Precision forging tongs for gripping and manipulating hot metal pieces.' }, { id: 5, name: 'Professional Chisel Set', price: 95, image: '/assets/chisels.png', description: 'Complete set of high-quality chisels for detailed metalwork and engraving.' }, { id: 6, name: 'Fire Forge Bucket', price: 180, image: '/assets/forge_fire_bucket.png', description: 'Portable coal forge bucket perfect for heating metals to forging temperature.' }, { id: 7, name: 'Steel Punches & Drifts', price: 75, image: '/assets/punches.png', description: 'Essential punch and drift set for creating holes and shaping metal.' }, { id: 8, name: 'Heavy-Duty Bench Vise', price: 220, image: '/assets/vise.png', description: 'Robust bench vise for secure workpiece holding during forging operations.' } ]; const handleSearch = () => { // Reset XSS flag if search is cleared if (search.trim() === '') { setXssTriggered(false); setSearchResults(''); return; } // XSS Vulnerability - Direct HTML injection without ANY sanitization const matchingProducts = products.filter(p => p.name.toLowerCase().includes(search.toLowerCase())); // Real XSS vulnerability - directly inserting user input into HTML // This will actually execute JavaScript when using event handlers if (matchingProducts.length > 0) { const productList = matchingProducts.map(p => `
${p.name} - $${p.price}
` ).join(''); setSearchResults(`

Search results for: ${search}

Found ${matchingProducts.length} products matching your query

${productList}
`); } else { setSearchResults(`

Search results for: ${search}

Found 0 products matching your query

`); } }; // Additional XSS vector - this useEffect will execute any script tags in the search results useEffect(() => { if (searchResults && searchResultsRef.current) { // This is EXTREMELY dangerous - executes any script tags in the content const scripts = searchResultsRef.current.querySelectorAll('script'); scripts.forEach(script => { const newScript = document.createElement('script'); newScript.textContent = script.textContent; document.body.appendChild(newScript); document.body.removeChild(newScript); }); // Check for XSS attempts and show flag notification (only once) if (!xssTriggered && (search.includes(')" : "Search tools..."} className={`input-field flex-1 ${hintsVisible ? 'border-red-500/30 focus:border-red-500' : ''}`} /> {/* XSS Vulnerability - Dangerous innerHTML */} {searchResults && (
)} {/* Subtle hint when hint mode is on */} {hintsVisible && (
Input not sanitized - Try: <script>alert('REAL_XSS')</script> or <img src=x onerror=alert('XSS')>
)}
{/* Products Grid */}

Our Tools

{products.map((product) => (
{product.name}

{product.name}

{product.description}

${product.price} View Details →
{hintsVisible && (
Product ID: {product.id}
)} ))}
); }