Apply security fixes

Implement security enhancements as suggested by the security review.
This commit is contained in:
gpt-engineer-app[bot] 2025-07-21 07:17:18 +00:00
parent cd588e391a
commit 9803c1a16c
5 changed files with 219 additions and 18 deletions

View file

@ -0,0 +1,76 @@
import React, { Component, ErrorInfo, ReactNode } from 'react';
import { AlertTriangle, RotateCcw } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
interface Props {
children: ReactNode;
fallback?: ReactNode;
}
interface State {
hasError: boolean;
error?: Error;
}
class ErrorBoundary extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error: Error): State {
// Update state so the next render will show the fallback UI
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
// Log error to console in development
if (process.env.NODE_ENV === 'development') {
console.error('Error caught by boundary:', error, errorInfo);
}
}
handleReset = () => {
this.setState({ hasError: false, error: undefined });
};
render() {
if (this.state.hasError) {
if (this.props.fallback) {
return this.props.fallback;
}
return (
<div className="min-h-screen flex items-center justify-center p-4">
<Card className="w-full max-w-md">
<CardHeader className="text-center">
<div className="flex justify-center mb-4">
<AlertTriangle className="w-12 h-12 text-destructive" />
</div>
<CardTitle className="text-xl">Something went wrong</CardTitle>
</CardHeader>
<CardContent className="text-center space-y-4">
<p className="text-muted-foreground">
We encountered an unexpected error. Please try refreshing the page or contact support if the problem persists.
</p>
<div className="flex flex-col sm:flex-row gap-2 justify-center">
<Button onClick={this.handleReset} variant="outline">
<RotateCcw className="w-4 h-4 mr-2" />
Try Again
</Button>
<Button onClick={() => window.location.reload()}>
Refresh Page
</Button>
</div>
</CardContent>
</Card>
</div>
);
}
return this.props.children;
}
}
export default ErrorBoundary;