From d000c51f0449045f9cf78e52f45ab0a1b8672a42 Mon Sep 17 00:00:00 2001 From: Sameer <142401625+sameer6pre@users.noreply.github.com> Date: Thu, 22 May 2025 09:57:24 +0530 Subject: [PATCH] Update orbit-app/src/components/CommentsSection.jsx in branch Precogs-fix-6nje451c --- orbit-app/src/components/CommentsSection.jsx | 30 +++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/orbit-app/src/components/CommentsSection.jsx b/orbit-app/src/components/CommentsSection.jsx index 6fe0c21..68018c2 100644 --- a/orbit-app/src/components/CommentsSection.jsx +++ b/orbit-app/src/components/CommentsSection.jsx @@ -6,16 +6,26 @@ function CommentsSection() { const [comment, setComment] = useState(''); const [commentsList, setCommentsList] = useState([]); - useEffect(() => { - // Fetch all comments - axios.get(`${BASE_URL}/comments`) - .then(response => { - setCommentsList(response.data); - }) - .catch(error => { - console.error('Error fetching comments:', error); - }); - }, []); +() => { + // Fetch all comments + const sanitizedBaseUrl = sanitizeUrl(BASE_URL); // Ensure BASE_URL is sanitized + axios.get(`${sanitizedBaseUrl}/comments`) + .then(response => { + setCommentsList(response.data); + }) + .catch(error => { + console.error('Error fetching comments:', error); + }); +} + +function sanitizeUrl(url) { + // Implement URL sanitization logic here + // For example, ensure the URL matches a specific pattern or whitelist + if (!/^https?:\/\//.test(url)) { + throw new Error('Invalid URL'); + } + return url; +} const handleSubmit = (e) => { e.preventDefault();