Skip to content

Commit

Permalink
Fix in-band sync URL
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r committed Nov 7, 2024
1 parent aff2a3c commit f226d03
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-actors-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"inngest": patch
---

Fix in-band sync URL
26 changes: 23 additions & 3 deletions packages/inngest/src/components/InngestCommHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { hashEventKey, hashSigningKey, stringify } from "../helpers/strings.js";
import { type MaybePromise } from "../helpers/types.js";
import {
functionConfigSchema,
inBandSyncRequestBodySchema,
logLevels,
type AuthenticatedIntrospection,
type EventPayload,
Expand Down Expand Up @@ -985,7 +986,7 @@ export class InngestCommHandler<
headers: Promise<Record<string, string>>;
}): Promise<ActionResponse> {
try {
const url = await actions.url("starting to handle request");
let url = await actions.url("starting to handle request");

if (method === "POST") {
const validationResult = await signatureValidation;
Expand Down Expand Up @@ -1220,8 +1221,27 @@ export class InngestCommHandler<
};
}

const res = inBandSyncRequestBodySchema.safeParse(body);
if (!res.success) {
return {
status: 400,
body: stringify({
code: "invalid_request",
message: res.error.message,
}),
headers: {
"Content-Type": "application/json",
},
version: undefined,
};
}

// We can trust the URL here because it's coming from
// signature-verified request.
url = this.reqUrl(new URL(res.data.url));

// This should be an in-band sync
const body = await this.inBandRegisterBody({
const respBody = await this.inBandRegisterBody({
actions,
deployId,
signatureValidation,
Expand All @@ -1230,7 +1250,7 @@ export class InngestCommHandler<

return {
status: 200,
body: stringify(body),
body: stringify(respBody),
headers: {
"Content-Type": "application/json",
[headerKeys.InngestSyncKind]: syncKind.InBand,
Expand Down
4 changes: 4 additions & 0 deletions packages/inngest/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,3 +1397,7 @@ export const ok = <T>(data: T): Result<T, never> => {
export const err = <E>(error?: E): Result<never, E> => {
return { ok: false, error };
};

export const inBandSyncRequestBodySchema = z.strictObject({
url: z.string(),
});

0 comments on commit f226d03

Please sign in to comment.