mirror of
https://github.com/documenso/documenso.git
synced 2026-07-26 01:45:08 +10:00
fix: make local provider robust to random input
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { jobsClient } from '@documenso/lib/jobs/client';
|
import { jobsClient } from '@documenso/lib/jobs/client';
|
||||||
import '@documenso/lib/jobs/definitions';
|
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
maxDuration: 300,
|
maxDuration: 300,
|
||||||
|
|||||||
@@ -5,16 +5,14 @@ import type { Json } from './json';
|
|||||||
export const ZTriggerJobOptionsSchema = z.object({
|
export const ZTriggerJobOptionsSchema = z.object({
|
||||||
id: z.string().optional(),
|
id: z.string().optional(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
payload: z.any().refine((x) => x !== undefined, { message: 'payload is required' }),
|
payload: z.unknown().refine((x) => x !== undefined, { message: 'payload is required' }),
|
||||||
timestamp: z.number().optional(),
|
timestamp: z.number().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// The Omit is a temporary workaround for a "bug" in the zod library
|
// The Omit is a temporary workaround for a "bug" in the zod library
|
||||||
// @see: https://github.com/colinhacks/zod/issues/2966
|
// @see: https://github.com/colinhacks/zod/issues/2966
|
||||||
export type TriggerJobOptions = Omit<z.infer<typeof ZTriggerJobOptionsSchema>, 'payload'> & {
|
export type TriggerJobOptions = Omit<z.infer<typeof ZTriggerJobOptionsSchema>, 'payload'> & {
|
||||||
// Don't tell the feds
|
payload: unknown;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
payload: any;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ import { BackgroundJobStatus, Prisma } from '@documenso/prisma/client';
|
|||||||
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
import { NEXT_PUBLIC_WEBAPP_URL } from '../../constants/app';
|
||||||
import { sign } from '../../server-only/crypto/sign';
|
import { sign } from '../../server-only/crypto/sign';
|
||||||
import { verify } from '../../server-only/crypto/verify';
|
import { verify } from '../../server-only/crypto/verify';
|
||||||
import type { JobDefinition, JobRunIO, TriggerJobOptions } from './_internal/job';
|
import {
|
||||||
|
type JobDefinition,
|
||||||
|
type JobRunIO,
|
||||||
|
type TriggerJobOptions,
|
||||||
|
ZTriggerJobOptionsSchema,
|
||||||
|
} from './_internal/job';
|
||||||
import type { Json } from './_internal/json';
|
import type { Json } from './_internal/json';
|
||||||
import { BaseJobProvider } from './base';
|
import { BaseJobProvider } from './base';
|
||||||
|
|
||||||
@@ -59,7 +64,8 @@ export class LocalJobProvider extends BaseJobProvider {
|
|||||||
jobId: job.id,
|
jobId: job.id,
|
||||||
name: job.name,
|
name: job.name,
|
||||||
version: job.version,
|
version: job.version,
|
||||||
payload: options.payload,
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
|
payload: options.payload as Prisma.InputJsonValue,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,7 +86,16 @@ export class LocalJobProvider extends BaseJobProvider {
|
|||||||
const isRetry = req.headers['x-job-retry'] !== undefined;
|
const isRetry = req.headers['x-job-retry'] !== undefined;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
const options = (await json(req)) as TriggerJobOptions;
|
const options = await json(req)
|
||||||
|
.then(async (data) => ZTriggerJobOptionsSchema.parseAsync(data))
|
||||||
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
|
.then((data) => data as TriggerJobOptions)
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
|
if (!options) {
|
||||||
|
res.status(400).send('Bad request');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const definition = this._jobDefinitions[options.name];
|
const definition = this._jobDefinitions[options.name];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user