From 797421f0d5a114f8c79eeff444c212c8a5b5f154 Mon Sep 17 00:00:00 2001 From: orangecoding Date: Wed, 28 Jan 2026 16:29:59 +0100 Subject: [PATCH] hardening demo handling --- lib/api/routes/jobRouter.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/api/routes/jobRouter.js b/lib/api/routes/jobRouter.js index 7333f4b..56553e2 100644 --- a/lib/api/routes/jobRouter.js +++ b/lib/api/routes/jobRouter.js @@ -11,10 +11,13 @@ import logger from '../../services/logger.js'; import { bus } from '../../services/events/event-bus.js'; import { isRunning as isJobRunning } from '../../services/jobs/run-state.js'; import { addClient as addSseClient, removeClient } from '../../services/sse/sse-broker.js'; +import { getSettings } from '../../services/storage/settingsStorage.js'; const service = restana(); const jobRouter = service.newRouter(); +const DEMO_JOB_NAME = 'Demo-Job'; + function doesJobBelongsToUser(job, req) { const userId = req.session.currentUser; if (userId == null) { @@ -161,6 +164,7 @@ jobRouter.post('/:jobId/run', async (req, res) => { jobRouter.post('/', async (req, res) => { const { provider, notificationAdapter, name, blacklist = [], jobId, enabled, shareWithUsers = [] } = req.body; + const settings = await getSettings(); try { let jobFromDb = jobStorage.getJob(jobId); @@ -169,6 +173,11 @@ jobRouter.post('/', async (req, res) => { return; } + if (settings.demoMode && jobFromDb.name === DEMO_JOB_NAME) { + res.send(new Error('Sorry, but you cannot change the Status of our Demo Job ;)')); + return; + } + jobStorage.upsertJob({ userId: req.session.currentUser, jobId, @@ -188,8 +197,14 @@ jobRouter.post('/', async (req, res) => { jobRouter.delete('', async (req, res) => { const { jobId } = req.body; + const settings = await getSettings(); try { const job = jobStorage.getJob(jobId); + if (settings.demoMode && job.name === DEMO_JOB_NAME) { + res.send(new Error('Sorry, but you cannot remove the Demo Job ;)')); + return; + } + if (!doesJobBelongsToUser(job, req)) { res.send(new Error('You are trying to remove a job that is not associated to your user')); } else { @@ -204,8 +219,15 @@ jobRouter.delete('', async (req, res) => { jobRouter.put('/:jobId/status', async (req, res) => { const { status } = req.body; const { jobId } = req.params; + const settings = await getSettings(); try { const job = jobStorage.getJob(jobId); + + if (settings.demoMode && job.name === DEMO_JOB_NAME) { + res.send(new Error('Sorry, but you cannot change the Status of our Demo Job ;)')); + return; + } + if (!doesJobBelongsToUser(job, req)) { res.send(new Error('You are trying change a job that is not associated to your user')); } else {