-
-
Notifications
You must be signed in to change notification settings - Fork 655
New Pull Request for Corrected Commit withtout corrupt files issue #2792 #3083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import QueueRoutes from "../routes/v1/queueRoute.js"; | |
| import LogRoutes from "../routes/v1/logRoutes.js"; | ||
| import DiagnosticRoutes from "../routes/v1//diagnosticRoute.js"; | ||
| import NotificationRoutes from "../routes/v1/notificationRoute.js"; | ||
| import SummaryRoutes from "../routes/v1/summaryRoute.js"; //for Homepage widget | ||
|
|
||
| import IncidentRoutes from "../routes/v1/incidentRoute.js"; | ||
|
|
||
|
|
@@ -42,4 +43,5 @@ export const setupRoutes = (app, controllers) => { | |
| app.use("/api/v1/notifications", verifyJWT, notificationRoutes.getRouter()); | ||
| app.use("/api/v1/diagnostic", verifyJWT, diagnosticRoutes.getRouter()); | ||
| app.use("/api/v1/incidents", verifyJWT, incidentRoutes.getRouter()); | ||
| app.use(SummaryRoutes); //used for Homepage widget | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Add authentication middleware to protect internal metrics. The Exposing these metrics without authentication is a security risk as it reveals:
This information could be valuable to attackers for reconnaissance. Apply this diff to add authentication: - app.use(SummaryRoutes); //used for Homepage widget
+ app.use("/api/v1", verifyJWT, SummaryRoutes); //used for Homepage widgetNote: You'll also need to update the route definition in
🤖 Prompt for AI Agents |
||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||
| import express from "express"; | ||||||||||||||
| import Monitor from "../../db/v1/models/Monitor.js"; | ||||||||||||||
| import Incident from "../../db/v1/models/Incident.js"; | ||||||||||||||
|
|
||||||||||||||
| const router = express.Router(); | ||||||||||||||
|
|
||||||||||||||
| router.get("/api/v1/summary", async (req, res) => { | ||||||||||||||
|
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: Medium The route definition contains the full
Suggested change
Evidence: path:server/src/routes/v1/summaryRoute.js, method:get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: Medium Speculative: The endpoint lacks comprehensive error handling and validation. While basic error handling exists, there's no validation of query parameters (if any are added later), no input sanitization, and no handling of edge cases like database connection failures beyond the general catch block. The API also doesn't document expected behavior or error responses. While the current implementation is minimal, establishing proper error patterns early prevents technical debt as the endpoint evolves. |
||||||||||||||
| try { | ||||||||||||||
| const [uptime, infrastructure, incidents] = await Promise.all([ | ||||||||||||||
| Monitor.countDocuments({ status: true, type: { $ne: "hardware" } }), | ||||||||||||||
| Monitor.countDocuments({ status: true, type: "hardware" }), | ||||||||||||||
| Incident.countDocuments({ status: true }) | ||||||||||||||
| ]); | ||||||||||||||
|
Comment on lines
+9
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 | Confidence: High The incident query uses Code Suggestion: Incident.countDocuments({ endTime: null }) // Assuming open incidents have no endTime
// OR
Incident.countDocuments({ status: "open" }) // If using string statusEvidence: path:server/src/routes/v1/summaryRoute.js, search:Incident.countDocuments |
||||||||||||||
| res.json({ uptime, infrastructure, incidents }); | ||||||||||||||
| } catch (error) { | ||||||||||||||
| console.error("Erreur /api/v1/summary :", error); | ||||||||||||||
| res.status(500).json({ error: "Erreur interne" }); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+15
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 | Confidence: High The error message is in French ("Erreur interne") while the rest of the codebase appears to use English. This creates inconsistency in the codebase and provides a confusing error message to users/developers who expect English messages. Consistent language usage is important for maintainability and developer experience.
Suggested change
Evidence: path:server/src/routes/v1/summaryRoute.js, search:Erreur |
||||||||||||||
| }); | ||||||||||||||
|
Comment on lines
+7
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Add authentication middleware and verify field semantics. This endpoint has several critical issues:
Apply this diff to fix the error messages: } catch (error) {
- console.error("Erreur /api/v1/summary :", error);
- res.status(500).json({ error: "Erreur interne" });
+ console.error("Error in /api/v1/summary:", error);
+ res.status(500).json({ error: "Internal server error" });
}For authentication, see the comment on routes.js line 46. For field semantics, run the following verification: #!/bin/bash
# Verify the schema definition for Monitor and Incident models to confirm field semantics
echo "=== Checking Monitor model schema ==="
rg -A 10 "status.*:" server/src/db/v1/models/Monitor.js
echo "=== Checking Incident model schema ==="
rg -A 10 "status.*:" server/src/db/v1/models/Incident.js
echo "=== Checking if 'isActive' or similar field exists ==="
rg -n "isActive|isUp|active" server/src/db/v1/models/🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| export default router; | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1 | Confidence: High
The route is mounted incorrectly, causing it to bypass all existing route configuration and middleware. The
app.use(SummaryRoutes)without a path prefix means the router's internal path (/api/v1/summary) is mounted at the root, creating a route at//api/v1/summary(double slash) which is malformed. More critically, it bypasses theverifyJWTmiddleware that protects all other/api/v1/*routes, making this endpoint publicly accessible without authentication. This violates the established security pattern of the application where all/api/v1/endpoints (except public ones like/api/v1/status-page) require authentication. This creates a security vulnerability by exposing potentially sensitive system metrics without authentication, and breaks architectural consistency./api/v1/diagnosticand/api/v1/incidentsroutes without following the established alphabetical or logical grouping pattern. Other routes are imported and registered in a consistent order. While not functionally incorrect, this inconsistency makes the code harder to maintain and scan. Following the established pattern improves code readability and maintainability.Evidence: path:server/src/config/routes.js, path:server/src/routes/v1/summaryRoute.js, search:app.use, search:SummaryRoutes