vibecodingreviewer
Version:
AI-powered code review tool with enhanced analysis
84 lines (72 loc) • 2.39 kB
JSX
// React component with intentional vulnerabilities and issues
import React, { useState, useEffect } from 'react';
import axios from 'axios';
// ISSUE: Hardcoded API endpoint
const API_BASE_URL = 'https://api.example.com';
// ISSUE: No error handling, missing keys, performance issues
function UserList({ userId }) {
const [users, setUsers] = useState([]);
const [loading, setLoading] = useState(false);
const [searchTerm, setSearchTerm] = useState('');
// ISSUE: Missing dependency array, potential memory leak
useEffect(() => {
fetchUsers();
});
// ISSUE: SQL injection vulnerability, no input validation
const fetchUsers = async () => {
setLoading(true);
try {
// ISSUE: Direct string concatenation with user input
const response = await axios.get(`${API_BASE_URL}/users?search=${searchTerm}`);
setUsers(response.data);
} catch (error) {
// ISSUE: Logging sensitive information
console.log('Error fetching users:', error.response.data);
} finally {
setLoading(false);
}
};
// ISSUE: Inefficient filtering, no memoization
const filteredUsers = users.filter(user =>
user.name.toLowerCase().includes(searchTerm.toLowerCase())
);
// ISSUE: Missing key prop, potential XSS vulnerability
const renderUsers = () => {
return filteredUsers.map(user => (
<div className="user-card">
<h3>{user.name}</h3>
<p>{user.email}</p>
<button onClick={() => deleteUser(user.id)}>
Delete User
</button>
</div>
));
};
// ISSUE: No authentication check, direct API call
const deleteUser = async (id) => {
try {
await axios.delete(`${API_BASE_URL}/users/${id}`);
setUsers(users.filter(user => user.id !== id));
} catch (error) {
// ISSUE: Exposing internal error details
alert(`Error: ${error.response.data.message}`);
}
};
// ISSUE: Inline styles, no CSS optimization
return (
<div style={{ padding: '20px' }}>
<input
type="text"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
placeholder="Search users..."
// ISSUE: No input sanitization
/>
{loading && <div>Loading...</div>}
<div className="users-container">
{renderUsers()}
</div>
</div>
);
}
export default UserList;