@dhaneshpurohit/mockstar 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/cli.js +198 -10
- package/dist/core/config/schema.d.ts +289 -155
- package/dist/core/config/schema.d.ts.map +1 -1
- package/dist/features/webhooks/dispatcher.d.ts.map +1 -1
- package/dist/features/webhooks/index.d.ts +3 -1
- package/dist/features/webhooks/index.d.ts.map +1 -1
- package/dist/features/webhooks/scheme.d.ts +46 -0
- package/dist/features/webhooks/scheme.d.ts.map +1 -0
- package/dist/features/webhooks/signing.d.ts +24 -13
- package/dist/features/webhooks/signing.d.ts.map +1 -1
- package/dist/features/webhooks/types.d.ts +17 -3
- package/dist/features/webhooks/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +202 -10
- package/dist/version.d.ts +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
# [0.3.0](https://github.com/dhanesh/mockstar/compare/v0.2.2...v0.3.0) (2026-09-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **webhooks:** close signing-config validation gaps from review round 2 ([62f6cf3](https://github.com/dhanesh/mockstar/commit/62f6cf37b8e157494076257213ebbcde56783cf0)), closes [#30](https://github.com/dhanesh/mockstar/issues/30) [#30](https://github.com/dhanesh/mockstar/issues/30)
|
|
7
|
+
* **webhooks:** convert JSDoc comments to line comments for RT-9 compliance ([70840e4](https://github.com/dhanesh/mockstar/commit/70840e4f6e1e0ac16e58611a94e818c75425fa18))
|
|
8
|
+
* **webhooks:** correct stale signing docs, reject {{ }} in signing templates, guard superRefine for future modes ([f62b1b0](https://github.com/dhanesh/mockstar/commit/f62b1b0f5b30d3091b791820ef796f03e36b76e4)), closes [#30](https://github.com/dhanesh/mockstar/issues/30)
|
|
9
|
+
* **webhooks:** give signing.mode a default so the emitted JSON Schema matches parse behaviour ([9a86781](https://github.com/dhanesh/mockstar/commit/9a8678131b88271671282fdd4a600d95edb22f15)), closes [#30](https://github.com/dhanesh/mockstar/issues/30)
|
|
10
|
+
* **webhooks:** tighten [#30](https://github.com/dhanesh/mockstar/issues/30) signing-scheme validation per code review ([b0b0ff7](https://github.com/dhanesh/mockstar/commit/b0b0ff752e358e35ff3965e7ec6c45df9ab8899d))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **webhooks:** add signature-scheme placeholder engine ([4c8f01c](https://github.com/dhanesh/mockstar/commit/4c8f01c23289d097a37474018eb14bd0b3fdc225)), closes [#30](https://github.com/dhanesh/mockstar/issues/30)
|
|
16
|
+
* **webhooks:** allow suppressing the standalone timestamp header ([#30](https://github.com/dhanesh/mockstar/issues/30)) ([661ec59](https://github.com/dhanesh/mockstar/commit/661ec5903084a8a684b5c34948ae40afe91b6bff))
|
|
17
|
+
* **webhooks:** emit the configured signature wire format ([762a794](https://github.com/dhanesh/mockstar/commit/762a7947455ae68bf8ff5f78dfe5ae3e08741a18)), closes [#30](https://github.com/dhanesh/mockstar/issues/30)
|
|
18
|
+
* **webhooks:** make signPayload/verifySignature scheme-aware ([f5c69ef](https://github.com/dhanesh/mockstar/commit/f5c69ef53367f9f73c06e25770516d2e91e3800e)), closes [#30](https://github.com/dhanesh/mockstar/issues/30)
|
|
19
|
+
* **webhooks:** model signing as a discriminated union on mode ([2890f36](https://github.com/dhanesh/mockstar/commit/2890f3649e9086856b44c517cd5e49c1e6c84f15)), closes [#30](https://github.com/dhanesh/mockstar/issues/30)
|
|
20
|
+
|
|
1
21
|
## [0.2.2](https://github.com/dhanesh/mockstar/compare/v0.2.1...v0.2.2) (2026-07-06)
|
|
2
22
|
|
|
3
23
|
|
package/dist/cli.js
CHANGED
|
@@ -1060,9 +1060,13 @@ function compileOne(spec) {
|
|
|
1060
1060
|
jitterRatio: spec.retry.jitterRatio
|
|
1061
1061
|
},
|
|
1062
1062
|
signing: spec.signing ? {
|
|
1063
|
+
mode: spec.signing.mode,
|
|
1063
1064
|
enabled: spec.signing.enabled,
|
|
1064
1065
|
algorithm: spec.signing.algorithm,
|
|
1065
1066
|
secretRef: spec.signing.secretRef,
|
|
1067
|
+
signedPayload: spec.signing.signedPayload,
|
|
1068
|
+
signatureTemplate: spec.signing.signatureTemplate,
|
|
1069
|
+
digestEncoding: spec.signing.digestEncoding,
|
|
1066
1070
|
signatureHeader: spec.signing.signatureHeader,
|
|
1067
1071
|
timestampHeader: spec.signing.timestampHeader,
|
|
1068
1072
|
replayWindowMs: spec.signing.replayWindowMs
|
|
@@ -6926,6 +6930,63 @@ var coerce = {
|
|
|
6926
6930
|
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
6927
6931
|
};
|
|
6928
6932
|
var NEVER = INVALID;
|
|
6933
|
+
// src/features/webhooks/scheme.ts
|
|
6934
|
+
var DEFAULT_SIGNED_PAYLOAD = "{timestamp}.{body}";
|
|
6935
|
+
var DEFAULT_SIGNATURE_TEMPLATE = "{algorithm}={signature}";
|
|
6936
|
+
var SIGNED_PAYLOAD_PLACEHOLDERS = ["body", "timestamp", "timestampSeconds"];
|
|
6937
|
+
var SIGNATURE_TEMPLATE_PLACEHOLDERS = [
|
|
6938
|
+
"signature",
|
|
6939
|
+
"algorithm",
|
|
6940
|
+
"timestamp",
|
|
6941
|
+
"timestampSeconds"
|
|
6942
|
+
];
|
|
6943
|
+
var PLACEHOLDER_RE = /\{([A-Za-z][A-Za-z0-9]*)\}/g;
|
|
6944
|
+
var UNKNOWN_PLACEHOLDER_SCAN_RE = /\{[^{}]*\}/g;
|
|
6945
|
+
function unknownPlaceholders(template, allowed) {
|
|
6946
|
+
const seen = new Set;
|
|
6947
|
+
const out = [];
|
|
6948
|
+
for (const match of template.matchAll(UNKNOWN_PLACEHOLDER_SCAN_RE)) {
|
|
6949
|
+
const name = match[0].slice(1, -1);
|
|
6950
|
+
if (name === "")
|
|
6951
|
+
continue;
|
|
6952
|
+
if (allowed.includes(name) || seen.has(name))
|
|
6953
|
+
continue;
|
|
6954
|
+
seen.add(name);
|
|
6955
|
+
out.push(name);
|
|
6956
|
+
}
|
|
6957
|
+
return out;
|
|
6958
|
+
}
|
|
6959
|
+
function hasUnbalancedPlaceholder(template) {
|
|
6960
|
+
const residue = template.replace(UNKNOWN_PLACEHOLDER_SCAN_RE, "");
|
|
6961
|
+
return /\{[A-Za-z]/.test(residue);
|
|
6962
|
+
}
|
|
6963
|
+
function substitute(template, values) {
|
|
6964
|
+
return template.replace(PLACEHOLDER_RE, (match, name) => Object.hasOwn(values, name) ? values[name] : match);
|
|
6965
|
+
}
|
|
6966
|
+
function renderSignedPayload(template, v) {
|
|
6967
|
+
return substitute(template, {
|
|
6968
|
+
body: v.body,
|
|
6969
|
+
timestamp: String(v.timestampMs),
|
|
6970
|
+
timestampSeconds: String(Math.floor(v.timestampMs / 1000))
|
|
6971
|
+
});
|
|
6972
|
+
}
|
|
6973
|
+
function renderSignatureHeader(template, v) {
|
|
6974
|
+
return substitute(template, {
|
|
6975
|
+
signature: v.signature,
|
|
6976
|
+
algorithm: v.algorithm,
|
|
6977
|
+
timestamp: String(v.timestampMs),
|
|
6978
|
+
timestampSeconds: String(Math.floor(v.timestampMs / 1000))
|
|
6979
|
+
});
|
|
6980
|
+
}
|
|
6981
|
+
function timestampUnitFor(scheme) {
|
|
6982
|
+
const combined = `${scheme.signedPayload} ${scheme.signatureTemplate}`;
|
|
6983
|
+
if (combined.includes("{timestamp}"))
|
|
6984
|
+
return "ms";
|
|
6985
|
+
if (combined.includes("{timestampSeconds}"))
|
|
6986
|
+
return "s";
|
|
6987
|
+
return null;
|
|
6988
|
+
}
|
|
6989
|
+
|
|
6929
6990
|
// src/core/config/schema.ts
|
|
6930
6991
|
var MatchMethod = exports_external.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "*"]);
|
|
6931
6992
|
var StringMatch = exports_external.union([
|
|
@@ -7007,16 +7068,105 @@ var ScenarioRule = exports_external.object({
|
|
|
7007
7068
|
response: ScenarioResponse
|
|
7008
7069
|
}).strict();
|
|
7009
7070
|
var SECRET_REF_RE = /^(\{\{\s*env\.[A-Z_][A-Z0-9_]*\s*\}\}|file:.+)$/;
|
|
7010
|
-
var
|
|
7071
|
+
var HmacSigning = exports_external.object({
|
|
7072
|
+
mode: exports_external.literal("hmac").default("hmac"),
|
|
7011
7073
|
enabled: exports_external.boolean().default(false),
|
|
7012
7074
|
algorithm: exports_external.literal("sha256").default("sha256"),
|
|
7013
7075
|
secretRef: exports_external.string().regex(SECRET_REF_RE, {
|
|
7014
7076
|
message: "webhook signing.secretRef must be `{{ env.NAME }}` or `file:/path`; inline secrets rejected (S3)"
|
|
7015
7077
|
}),
|
|
7078
|
+
signedPayload: exports_external.string().min(1).default(DEFAULT_SIGNED_PAYLOAD),
|
|
7079
|
+
signatureTemplate: exports_external.string().min(1).default(DEFAULT_SIGNATURE_TEMPLATE),
|
|
7080
|
+
digestEncoding: exports_external.enum(["hex", "base64"]).default("hex"),
|
|
7016
7081
|
signatureHeader: exports_external.string().min(1).default("x-mockstar-signature"),
|
|
7017
|
-
timestampHeader: exports_external.string().min(1).default("x-mockstar-timestamp"),
|
|
7082
|
+
timestampHeader: exports_external.string().min(1).nullable().default("x-mockstar-timestamp"),
|
|
7018
7083
|
replayWindowMs: exports_external.number().int().positive().default(300000)
|
|
7019
7084
|
}).strict();
|
|
7085
|
+
var WebhookSigning = exports_external.preprocess((raw) => raw !== null && typeof raw === "object" && !Array.isArray(raw) && !("mode" in raw) ? { ...raw, mode: "hmac" } : raw, exports_external.discriminatedUnion("mode", [HmacSigning])).superRefine((v, ctx) => {
|
|
7086
|
+
if (typeof v.signedPayload !== "string" || typeof v.signatureTemplate !== "string")
|
|
7087
|
+
return;
|
|
7088
|
+
const fmt = (names) => names.map((n) => `{${n}}`).join(", ");
|
|
7089
|
+
const signedPayloadHasDoubleBrace = v.signedPayload.includes("{{");
|
|
7090
|
+
if (signedPayloadHasDoubleBrace) {
|
|
7091
|
+
ctx.addIssue({
|
|
7092
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7093
|
+
path: ["signedPayload"],
|
|
7094
|
+
message: "signedPayload uses single-brace placeholders (e.g. {body}), not the {{ }} request-template syntax \u2014 did you mean {body} instead of {{ body }}?"
|
|
7095
|
+
});
|
|
7096
|
+
}
|
|
7097
|
+
const signatureTemplateHasDoubleBrace = v.signatureTemplate.includes("{{");
|
|
7098
|
+
if (signatureTemplateHasDoubleBrace) {
|
|
7099
|
+
ctx.addIssue({
|
|
7100
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7101
|
+
path: ["signatureTemplate"],
|
|
7102
|
+
message: "signatureTemplate uses single-brace placeholders (e.g. {signature}), not the {{ }} request-template syntax \u2014 did you mean {signature} instead of {{ signature }}?"
|
|
7103
|
+
});
|
|
7104
|
+
}
|
|
7105
|
+
const signedPayloadHasTemplateLiteral = v.signedPayload.includes("${");
|
|
7106
|
+
if (signedPayloadHasTemplateLiteral) {
|
|
7107
|
+
ctx.addIssue({
|
|
7108
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7109
|
+
path: ["signedPayload"],
|
|
7110
|
+
message: "signedPayload uses single-brace placeholders (e.g. {body}), not JS template-literal syntax \u2014 did you mean {body} instead of ${body}?"
|
|
7111
|
+
});
|
|
7112
|
+
}
|
|
7113
|
+
const signatureTemplateHasTemplateLiteral = v.signatureTemplate.includes("${");
|
|
7114
|
+
if (signatureTemplateHasTemplateLiteral) {
|
|
7115
|
+
ctx.addIssue({
|
|
7116
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7117
|
+
path: ["signatureTemplate"],
|
|
7118
|
+
message: "signatureTemplate uses single-brace placeholders (e.g. {signature}), not JS template-literal syntax \u2014 did you mean {signature} instead of ${signature}?"
|
|
7119
|
+
});
|
|
7120
|
+
}
|
|
7121
|
+
if (!signedPayloadHasDoubleBrace && !signedPayloadHasTemplateLiteral) {
|
|
7122
|
+
const badPayload = unknownPlaceholders(v.signedPayload, SIGNED_PAYLOAD_PLACEHOLDERS);
|
|
7123
|
+
if (badPayload.length > 0) {
|
|
7124
|
+
ctx.addIssue({
|
|
7125
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7126
|
+
path: ["signedPayload"],
|
|
7127
|
+
message: `unknown placeholder(s) ${fmt(badPayload)} \u2014 allowed: ${fmt(SIGNED_PAYLOAD_PLACEHOLDERS)}`
|
|
7128
|
+
});
|
|
7129
|
+
}
|
|
7130
|
+
if (!v.signedPayload.includes("{body}")) {
|
|
7131
|
+
ctx.addIssue({
|
|
7132
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7133
|
+
path: ["signedPayload"],
|
|
7134
|
+
message: "signedPayload must contain {body} \u2014 otherwise the signature covers no request content"
|
|
7135
|
+
});
|
|
7136
|
+
}
|
|
7137
|
+
if (hasUnbalancedPlaceholder(v.signedPayload)) {
|
|
7138
|
+
ctx.addIssue({
|
|
7139
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7140
|
+
path: ["signedPayload"],
|
|
7141
|
+
message: "signedPayload has an unmatched { that looks like an unterminated placeholder \u2014 check for a missing closing brace"
|
|
7142
|
+
});
|
|
7143
|
+
}
|
|
7144
|
+
}
|
|
7145
|
+
if (!signatureTemplateHasDoubleBrace && !signatureTemplateHasTemplateLiteral) {
|
|
7146
|
+
const badTemplate = unknownPlaceholders(v.signatureTemplate, SIGNATURE_TEMPLATE_PLACEHOLDERS);
|
|
7147
|
+
if (badTemplate.length > 0) {
|
|
7148
|
+
ctx.addIssue({
|
|
7149
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7150
|
+
path: ["signatureTemplate"],
|
|
7151
|
+
message: `unknown placeholder(s) ${fmt(badTemplate)} \u2014 allowed: ${fmt(SIGNATURE_TEMPLATE_PLACEHOLDERS)}`
|
|
7152
|
+
});
|
|
7153
|
+
}
|
|
7154
|
+
if (!v.signatureTemplate.includes("{signature}")) {
|
|
7155
|
+
ctx.addIssue({
|
|
7156
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7157
|
+
path: ["signatureTemplate"],
|
|
7158
|
+
message: "signatureTemplate must contain {signature} \u2014 otherwise the signature header carries no digest"
|
|
7159
|
+
});
|
|
7160
|
+
}
|
|
7161
|
+
if (hasUnbalancedPlaceholder(v.signatureTemplate)) {
|
|
7162
|
+
ctx.addIssue({
|
|
7163
|
+
code: exports_external.ZodIssueCode.custom,
|
|
7164
|
+
path: ["signatureTemplate"],
|
|
7165
|
+
message: "signatureTemplate has an unmatched { that looks like an unterminated placeholder \u2014 check for a missing closing brace"
|
|
7166
|
+
});
|
|
7167
|
+
}
|
|
7168
|
+
}
|
|
7169
|
+
});
|
|
7020
7170
|
var WebhookRetry = exports_external.object({
|
|
7021
7171
|
attempts: exports_external.number().int().min(1).max(20).default(6),
|
|
7022
7172
|
backoff: exports_external.array(exports_external.number().int().nonnegative()).default([1000, 2000, 4000, 8000, 16000]),
|
|
@@ -11502,7 +11652,7 @@ function adminRouter(deps) {
|
|
|
11502
11652
|
entryId,
|
|
11503
11653
|
id: spec.id,
|
|
11504
11654
|
method: spec.method,
|
|
11505
|
-
signing: spec.signing ? { enabled: spec.signing.enabled, algorithm: spec.signing.algorithm } : null,
|
|
11655
|
+
signing: spec.signing ? { mode: spec.signing.mode, enabled: spec.signing.enabled, algorithm: spec.signing.algorithm } : null,
|
|
11506
11656
|
retry: { attempts: spec.retry.attempts },
|
|
11507
11657
|
circuit: spec.circuit,
|
|
11508
11658
|
timeoutMs: spec.timeoutMs,
|
|
@@ -12578,9 +12728,33 @@ class WebhookJournalRegistry {
|
|
|
12578
12728
|
}
|
|
12579
12729
|
// src/features/webhooks/signing.ts
|
|
12580
12730
|
import { createHmac, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12731
|
+
var LEGACY_SCHEME = Object.freeze({
|
|
12732
|
+
signedPayload: DEFAULT_SIGNED_PAYLOAD,
|
|
12733
|
+
signatureTemplate: DEFAULT_SIGNATURE_TEMPLATE,
|
|
12734
|
+
digestEncoding: "hex",
|
|
12735
|
+
algorithm: "sha256"
|
|
12736
|
+
});
|
|
12737
|
+
function signPayload(rawBody, secret, timestampMs, scheme = LEGACY_SCHEME) {
|
|
12738
|
+
const stringToSign = renderSignedPayload(scheme.signedPayload, { body: rawBody, timestampMs });
|
|
12739
|
+
return createHmac(scheme.algorithm, secret).update(stringToSign, "utf8").digest(scheme.digestEncoding);
|
|
12740
|
+
}
|
|
12741
|
+
function verifySignature(rawBody, secret, timestampMs, signature, scheme = LEGACY_SCHEME) {
|
|
12742
|
+
try {
|
|
12743
|
+
const expected = signPayload(rawBody, secret, timestampMs, scheme);
|
|
12744
|
+
if (expected.length !== signature.length)
|
|
12745
|
+
return false;
|
|
12746
|
+
const a2 = Buffer.from(expected, scheme.digestEncoding);
|
|
12747
|
+
const b2 = Buffer.from(signature, scheme.digestEncoding);
|
|
12748
|
+
if (a2.length !== b2.length || a2.length === 0)
|
|
12749
|
+
return false;
|
|
12750
|
+
return timingSafeEqual2(a2, b2);
|
|
12751
|
+
} catch {
|
|
12752
|
+
return false;
|
|
12753
|
+
}
|
|
12754
|
+
}
|
|
12755
|
+
function withinReplayWindow(timestampMs, windowMs, nowMs = Date.now(), futureSkewMs = 60000) {
|
|
12756
|
+
const delta = nowMs - timestampMs;
|
|
12757
|
+
return delta <= windowMs && delta >= -futureSkewMs;
|
|
12584
12758
|
}
|
|
12585
12759
|
function resolveSecret(secretRef) {
|
|
12586
12760
|
const envMatch = secretRef.match(/^\{\{\s*env\.([A-Z_][A-Z0-9_]*)\s*\}\}$/);
|
|
@@ -12661,9 +12835,23 @@ async function performAttempt(spec, input, _deps) {
|
|
|
12661
12835
|
if (spec.signing?.enabled) {
|
|
12662
12836
|
const secret = resolveSecret(spec.signing.secretRef);
|
|
12663
12837
|
const timestampMs = Date.now();
|
|
12664
|
-
const
|
|
12665
|
-
|
|
12666
|
-
|
|
12838
|
+
const scheme = {
|
|
12839
|
+
signedPayload: spec.signing.signedPayload,
|
|
12840
|
+
signatureTemplate: spec.signing.signatureTemplate,
|
|
12841
|
+
digestEncoding: spec.signing.digestEncoding,
|
|
12842
|
+
algorithm: spec.signing.algorithm
|
|
12843
|
+
};
|
|
12844
|
+
const signature = signPayload(rawBody, secret, timestampMs, scheme);
|
|
12845
|
+
renderedHeaders.set(spec.signing.signatureHeader, renderSignatureHeader(scheme.signatureTemplate, {
|
|
12846
|
+
signature,
|
|
12847
|
+
algorithm: scheme.algorithm,
|
|
12848
|
+
timestampMs
|
|
12849
|
+
}));
|
|
12850
|
+
const unit = timestampUnitFor(scheme);
|
|
12851
|
+
if (unit !== null && spec.signing.timestampHeader !== null) {
|
|
12852
|
+
const value = unit === "s" ? Math.floor(timestampMs / 1000) : timestampMs;
|
|
12853
|
+
renderedHeaders.set(spec.signing.timestampHeader, String(value));
|
|
12854
|
+
}
|
|
12667
12855
|
}
|
|
12668
12856
|
if (!renderedHeaders.has("x-mockstar-delivery-id")) {
|
|
12669
12857
|
renderedHeaders.set("x-mockstar-delivery-id", input.triggerRequestId);
|
|
@@ -14914,7 +15102,7 @@ function proxyHelp() {
|
|
|
14914
15102
|
}
|
|
14915
15103
|
|
|
14916
15104
|
// src/version.ts
|
|
14917
|
-
var MOCKSTAR_VERSION = "0.
|
|
15105
|
+
var MOCKSTAR_VERSION = "0.3.0";
|
|
14918
15106
|
|
|
14919
15107
|
// src/cli.ts
|
|
14920
15108
|
function parseArgs(argv) {
|