Skip to content

pull#57

Merged
MIbnEKhalid merged 12 commits intoTestfrom
main
May 4, 2025
Merged

pull#57
MIbnEKhalid merged 12 commits intoTestfrom
main

Conversation

@MIbnEKhalid
Copy link
Copy Markdown
Owner

No description provided.

MIbnEKhalid and others added 12 commits April 12, 2025 09:06
Refactor authentication and session management
- Introduced a delete button for each message that appears on hover.
- Implemented a confirmation prompt before deleting a message.
- Added event delegation for handling delete button clicks.
- Enhanced the chat model selection dropdown with optgroups for better organization.
- Adjusted styling for overlays and buttons for improved user experience.
- Updated the message addition logic to include unique message IDs.
…dding loading animations; improve UI elements for better user experience
console.log(`Message with ID: ${messageId} successfully deleted from Chat ID: ${chatId}`);
res.json({ success: true, message: "Message deleted" });
} catch (error) {
console.error(`Error deleting message with ID: ${messageId} from Chat ID: ${chatId}`, error);

Check failure

Code scanning / CodeQL

Use of externally-controlled format string High

Format string depends on a
user-provided value
.
Format string depends on a
user-provided value
.

Copilot Autofix

AI 11 months ago

To address the issue, we will modify the flagged line to use a safer approach by explicitly formatting the untrusted input using %s placeholders. This ensures that the untrusted values are treated as plain strings, regardless of their content. The fix will involve replacing the template literal with a format string and passing the untrusted values as separate arguments to console.error.


Suggested changeset 1
routes/main.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/routes/main.js b/routes/main.js
--- a/routes/main.js
+++ b/routes/main.js
@@ -583,3 +583,3 @@
   } catch (error) {
-    console.error(`Error deleting message with ID: ${messageId} from Chat ID: ${chatId}`, error);
+    console.error("Error deleting message with ID: %s from Chat ID: %s", messageId, chatId, error);
     handleApiError(res, error, "deleting message");
EOF
@@ -583,3 +583,3 @@
} catch (error) {
console.error(`Error deleting message with ID: ${messageId} from Chat ID: ${chatId}`, error);
console.error("Error deleting message with ID: %s from Chat ID: %s", messageId, chatId, error);
handleApiError(res, error, "deleting message");
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
return res.status(500).json({ message: "Logout failed." });
}
res.json({ message: "Logged out successfully." });
router.post('/api/bot-chat', checkMessageLimit, async (req, res) => {

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.
This route handler performs
a database access
, but is not rate-limited.

Copilot Autofix

AI 11 months ago

To address the issue, we will add rate limiting to the /api/bot-chat route using the express-rate-limit package. This middleware will restrict the number of requests a client can make to the route within a specified time window. Specifically:

  1. Install the express-rate-limit package if it is not already installed.
  2. Configure a rate limiter with appropriate settings (e.g., a maximum of 100 requests per 15 minutes).
  3. Apply the rate limiter middleware to the /api/bot-chat route.

This fix ensures that the route is protected against abuse while maintaining its functionality.


Suggested changeset 2
routes/main.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/routes/main.js b/routes/main.js
--- a/routes/main.js
+++ b/routes/main.js
@@ -3,2 +3,3 @@
 import fetch from 'node-fetch';
+import rateLimit from "express-rate-limit";
 import { pool } from "./pool.js";
@@ -588,3 +589,9 @@
 
-router.post('/api/bot-chat', checkMessageLimit, async (req, res) => {
+const botChatRateLimiter = rateLimit({
+  windowMs: 15 * 60 * 1000, // 15 minutes
+  max: 100, // Limit each IP to 100 requests per windowMs
+  message: "Too many requests to /api/bot-chat. Please try again later."
+});
+
+router.post('/api/bot-chat', botChatRateLimiter, checkMessageLimit, async (req, res) => {
   const { message, chatId } = req.body;
EOF
@@ -3,2 +3,3 @@
import fetch from 'node-fetch';
import rateLimit from "express-rate-limit";
import { pool } from "./pool.js";
@@ -588,3 +589,9 @@

router.post('/api/bot-chat', checkMessageLimit, async (req, res) => {
const botChatRateLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per windowMs
message: "Too many requests to /api/bot-chat. Please try again later."
});

router.post('/api/bot-chat', botChatRateLimiter, checkMessageLimit, async (req, res) => {
const { message, chatId } = req.body;
package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -28,3 +28,4 @@
     "node-fetch": "^3.3.2",
-    "pg": "^8.13.1"
+    "pg": "^8.13.1",
+    "express-rate-limit": "^7.5.0"
   },
EOF
@@ -28,3 +28,4 @@
"node-fetch": "^3.3.2",
"pg": "^8.13.1"
"pg": "^8.13.1",
"express-rate-limit": "^7.5.0"
},
This fix introduces these dependencies
Package Version Security advisories
express-rate-limit (npm) 7.5.0 None
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Comment on lines +667 to +677
router.post('/api/chat/clear-history/:chatId', validateSessionAndRole("Any"), async (req, res) => {
const { chatId } = req.params;
if (!chatId) return res.status(400).json({ message: "Chat ID is required" });

try {
await pool.query('DELETE FROM Ai_history WHERE id = $1', [chatId]);
res.json({ status: 200, message: "Chat history deleted", chatId });
} catch (error) {
handleApiError(res, error, "deleting chat history");
}
});

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.

Copilot Autofix

AI 11 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

@vercel
Copy link
Copy Markdown

vercel bot commented May 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
chat-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 4, 2025 6:23pm

@MIbnEKhalid MIbnEKhalid merged commit e851fef into Test May 4, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants