Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: validate job skill template names and gate their save as host control (#8762)

[._.]/ Adam Eivyec63af2c7921
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.js
index 023fbb6ddd..e014d2355c 100644
--- a/server/lib/hostControlRoutes.js
+++ b/server/lib/hostControlRoutes.js
@@ -109,6 +109,8 @@ export const HOST_CONTROL_ROUTES = Object.freeze([
// Toggle arms an existing job, shell jobs included, for its next run.
'POST /api/cos/jobs/:id/toggle',
'POST /api/cos/jobs/:id/trigger',
+ // A job skill template IS the prompt a scheduled job's agent runs (#8762).
+ 'PUT /api/prompts/skills/jobs/:name',
'PUT /api/cos/schedule/task/:taskType',
'POST /api/cos/schedule/trigger',
'POST /api/cos/schedule/maintenance-runs',
diff --git a/server/routes/promptsJobSkills.test.js b/server/routes/promptsJobSkills.test.js
new file mode 100644
index 0000000000..f510723b12
--- /dev/null
+++ b/server/routes/promptsJobSkills.test.js
@@ -0,0 +1,80 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import express from 'express';
+import { errorMiddleware } from '../lib/errorHandler.js';
+import { request } from '../lib/testHelper.js';
+
+// Job skill template routes (#8762): the name is a URL segment Express has
+// already decoded, so it must never reach the filesystem unchecked, and the
+// save is host control — a skill template is the prompt a job's agent runs.
+vi.mock('../services/auth.js', async (importOriginal) => ({
+ ...await importOriginal(),
+ isAuthEnabled: vi.fn().mockResolvedValue(false),
+}));
+
+const fsCalls = vi.hoisted(() => ({ write: vi.fn(async () => {}), read: vi.fn(async () => 'template body') }));
+vi.mock('../lib/fileUtils.js', async (importOriginal) => ({
+ ...await importOriginal(),
+ ensureDir: vi.fn(async () => {}),
+ writeFileGuarded: fsCalls.write,
+ tryReadFile: fsCalls.read,
+}));
+
+vi.mock('../services/autonomousJobs.js', async () => {
+ const templates = await vi.importActual('../services/autonomousJobs/skillTemplates.js');
+ const { JOB_SKILL_MAP } = await vi.importActual('../services/autonomousJobs/constants.js');
+ return {
+ listJobSkillTemplates: vi.fn(async () => []),
+ loadJobSkillTemplate: templates.loadJobSkillTemplate,
+ saveJobSkillTemplate: templates.saveJobSkillTemplate,
+ getJobEffectivePrompt: vi.fn(async () => ''),
+ getJob: vi.fn(async () => null),
+ JOB_SKILL_MAP,
+ };
+});
+
+import { authGate, hostControlRouteGate } from '../services/authGate.js';
+import { JOB_SKILL_MAP } from '../services/autonomousJobs/constants.js';
+import { createPortOSPromptsRoutes } from './prompts.js';
+
+const SKILL = Object.values(JOB_SKILL_MAP)[0];
+
+const buildApp = (remoteAddress) => {
+ const app = express();
+ app.use((req, _res, next) => {
+ Object.defineProperty(req.socket, 'remoteAddress', { value: remoteAddress });
+ next();
+ });
+ app.use(authGate);
+ app.use(hostControlRouteGate);
+ app.use(express.json());
+ app.use('/api/prompts', createPortOSPromptsRoutes({ services: { prompts: {} } }));
+ app.use(errorMiddleware);
+ return app;
+};
+
+describe('job skill template routes (#8762)', () => {
+ beforeEach(() => vi.clearAllMocks());
+
+ it('rejects a traversal or unknown name with 400 and touches no file', async () => {
+ for (const name of ['..%2F..%2Fx', '..%2FAGENTS', 'not-a-known-skill']) {
+ const put = await request(buildApp('127.0.0.1')).put(`/api/prompts/skills/jobs/${name}`).send({ content: 'x' });
+ expect(put.status).toBe(400);
+ const get = await request(buildApp('127.0.0.1')).get(`/api/prompts/skills/jobs/${name}`);
+ expect(get.status).toBe(400);
+ }
+ expect(fsCalls.write).not.toHaveBeenCalled();
+ expect(fsCalls.read).not.toHaveBeenCalled();
+ });
+
+ it('refuses a remote password-free caller and lets the local operator save', async () => {
+ const remote = await request(buildApp('192.0.2.10')).put(`/api/prompts/skills/jobs/${SKILL}`).send({ content: 'x' });
+ expect(remote.status).toBe(403);
+ expect(remote.body.code).toBe('HOST_CONTROL_FORBIDDEN');
+ expect(fsCalls.write).not.toHaveBeenCalled();
+
+ const local = await request(buildApp('127.0.0.1')).put(`/api/prompts/skills/jobs/${SKILL}`).send({ content: 'x' });
+ expect(local.status).toBe(200);
+ expect(fsCalls.write).toHaveBeenCalledTimes(1);
+ expect(fsCalls.write.mock.calls[0][0]).toMatch(new RegExp(`${SKILL}\\.md$`));
+ });
+});
diff --git a/server/services/autonomousJobs/skillTemplates.js b/server/services/autonomousJobs/skillTemplates.js
index 4e4a38b37f..c80163c992 100644
--- a/server/services/autonomousJobs/skillTemplates.js
+++ b/server/services/autonomousJobs/skillTemplates.js
@@ -14,6 +14,21 @@ import { getAppById } from '../apps.js'
import { appendTaskDataInputs, resolveTaskDataInputs } from '../taskDataInputs.js'
import { appendJobFormValues } from '../../lib/jobFormFields.js'
import { FILE_ISSUES_DELIVERY_SETTINGS, isExplicitFileIssuesRequest } from '../../lib/auditCatalog.js'
+import { ServerError } from '../../lib/errorHandler.js'
+
+const KNOWN_SKILL_NAMES = new Set(Object.values(JOB_SKILL_MAP))
+
+/**
+ * Resolve a skill name to its template path, refusing anything but a known
+ * job skill — the name arrives from a URL segment, where Express has already
+ * decoded `%2F`, so an unchecked name could reach any `.md` file (#8762).
+ */
+function jobSkillTemplatePath(skillName) {
+ if (typeof skillName !== 'string' || !/^[a-z0-9-]+$/.test(skillName) || !KNOWN_SKILL_NAMES.has(skillName)) {
+ throw new ServerError('Unknown job skill template', { status: 400, code: 'VALIDATION_ERROR' })
+ }
+ return join(JOBS_SKILLS_DIR, `${skillName}.md`)
+}
/**
* Load a job skill template from disk
@@ -21,7 +36,7 @@ import { FILE_ISSUES_DELIVERY_SETTINGS, isExplicitFileIssuesRequest } from '../.
* @returns {Promise<string|null>} Template content or null if not found
*/
async function loadJobSkillTemplate(skillName) {
- const filePath = join(JOBS_SKILLS_DIR, `${skillName}.md`)
+ const filePath = jobSkillTemplatePath(skillName)
const content = await tryReadFile(filePath)
if (content) {
console.log(`🎯 Loaded job skill template: ${skillName}`)
@@ -36,7 +51,7 @@ async function loadJobSkillTemplate(skillName) {
*/
async function saveJobSkillTemplate(skillName, content) {
await ensureDir(JOBS_SKILLS_DIR)
- const filePath = join(JOBS_SKILLS_DIR, `${skillName}.md`)
+ const filePath = jobSkillTemplatePath(skillName)
await writeFileGuarded(filePath, content)
console.log(`💾 Saved job skill template: ${skillName}`)
}