notifications-backend: avoid use of insecure express response patterns

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-09-16 12:53:05 +02:00
parent ffe31a8ae0
commit 1c6f1424bd
2 changed files with 11 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-notifications-backend': patch
---
Internal refactor to avoid use of insecure coding patterns.
@@ -28,7 +28,7 @@ import {
NotificationProcessor,
NotificationSendOptions,
} from '@backstage/plugin-notifications-node';
import { InputError } from '@backstage/errors';
import { InputError, NotFoundError } from '@backstage/errors';
import {
AuthService,
HttpAuthService,
@@ -249,7 +249,7 @@ export async function createRouter(
store.getNotifications(opts),
store.getNotificationsCount(opts),
]);
res.send({
res.json({
totalCount,
notifications,
});
@@ -258,7 +258,7 @@ export async function createRouter(
router.get('/status', async (req: Request<any, NotificationStatus>, res) => {
const user = await getUser(req);
const status = await store.getStatus({ user });
res.send(status);
res.json(status);
});
// Make sure this is the last "GET" handler
@@ -271,10 +271,9 @@ export async function createRouter(
};
const notifications = await store.getNotifications(opts);
if (notifications.length !== 1) {
res.status(404).send({ error: 'Not found' });
return;
throw new NotFoundError('Not found');
}
res.send(notifications[0]);
res.json(notifications[0]);
});
router.post('/update', async (req, res) => {
@@ -313,7 +312,7 @@ export async function createRouter(
}
const notifications = await store.getNotifications({ ids, user: user });
res.status(200).send(notifications);
res.json(notifications);
});
const sendBroadcastNotification = async (