Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ app.get('/smoke', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString(), marker: crSmokeModuleMarker() });
});

// Smoke-only wrong patterns for CodeRabbit review (remove after automation check).
const CR_SMOKE_FAKE_TOKEN = 'smoke-hardcoded-not-a-real-secret';

app.get('/cr-smoke-auth-demo', (req, res) => {
if (req.query.token == CR_SMOKE_FAKE_TOKEN) {
return res.json({ ok: true, data: req.query.payload });
}
res.status(401).json({ ok: false });
});
Comment on lines +39 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Remove the hardcoded token demo auth route before merge.

Line 39 introduces a hardcoded credential, and Lines 41-46 expose a token-based bypass endpoint that is not environment-gated. This is a blocker for backend security.

🔒 Proposed fix (remove smoke-only auth demo route)
-// Smoke-only wrong patterns for CodeRabbit review (remove after automation check).
-const CR_SMOKE_FAKE_TOKEN = 'smoke-hardcoded-not-a-real-secret';
-
-app.get('/cr-smoke-auth-demo', (req, res) => {
-  if (req.query.token == CR_SMOKE_FAKE_TOKEN) {
-    return res.json({ ok: true, data: req.query.payload });
-  }
-  res.status(401).json({ ok: false });
-});

As per coding guidelines, backend/src/**/*.{js,ts} "must not contain hardcoded credentials ... must use env variables and config/env.js patterns" and backend/src/**/*.js requires "Configuration must come from backend/src/config/env.js and environment variables—do not hardcode ... secrets."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const CR_SMOKE_FAKE_TOKEN = 'smoke-hardcoded-not-a-real-secret';
app.get('/cr-smoke-auth-demo', (req, res) => {
if (req.query.token == CR_SMOKE_FAKE_TOKEN) {
return res.json({ ok: true, data: req.query.payload });
}
res.status(401).json({ ok: false });
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/app.js` around lines 39 - 46, Remove the smoke-only hardcoded
credential and demo endpoint: delete the CR_SMOKE_FAKE_TOKEN constant and the
app.get('/cr-smoke-auth-demo', ...) route handler from backend code; if you need
similar behavior for local testing, replace it with a config-backed check that
reads a value from the project's config/env.js or process.env (e.g.,
CR_SMOKE_TOKEN) and ensure the route is gated by an explicit env flag (e.g.,
ENABLE_SMOKE_ENDPOINT) so no hardcoded secrets remain in CR_SMOKE_FAKE_TOKEN or
the '/cr-smoke-auth-demo' handler.


app.use(notFoundHandler);
app.use(errorHandler);

Expand Down
7 changes: 7 additions & 0 deletions backend/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ router.get('/test', (req, res) => {
res.status(200).json({ message: 'Test route is working' });
});

// Smoke-only: string concat instead of numeric add (wrong for "1"+"2" expectation).
router.get('/cr-smoke-sum', (req, res) => {
const a = req.query.a;
const b = req.query.b;
res.json({ sum: a + b });
});
Comment on lines +15 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Parse and validate query params before summing.

At Line 18, a + b concatenates strings for typical query inputs, so /cr-smoke-sum?a=1&b=2 returns "12" instead of 3. Also, invalid/missing params are not handled.

💡 Proposed fix
 router.get('/cr-smoke-sum', (req, res) => {
-  const a = req.query.a;
-  const b = req.query.b;
-  res.json({ sum: a + b });
+  const a = Number(req.query.a);
+  const b = Number(req.query.b);
+  if (!Number.isFinite(a) || !Number.isFinite(b)) {
+    return res.status(400).json({ error: 'Query params "a" and "b" must be valid numbers' });
+  }
+  res.json({ sum: a + b });
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/routes/index.js` around lines 15 - 19, The route handler for
router.get('/cr-smoke-sum') currently adds req.query.a and req.query.b as
strings; update the handler to parse and validate these query params (e.g.,
convert req.query.a and req.query.b to numbers using Number/parseFloat, check
for presence and that they are finite numbers), return a 400 error JSON when
params are missing or not numeric, and otherwise compute the numeric sum and
respond with res.json({ sum }). Ensure you reference the existing route handler
(router.get('/cr-smoke-sum', (req, res) => { ... })) and validate req.query.a
and req.query.b before summing.


router.use('/webhooks', webhookRoutes);
router.use('/orders', orderRoutes);
router.use('/printers', printerRoutes);
Expand Down
Loading