Skip to content

Commit a76d799

Browse files
authored
Check for value of encodedAttribute and better payload safety checks (#978)
* Check for value of encodedAttribute and better payload safety checks * Remove if statement
1 parent 61ef88b commit a76d799

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@temporalio/ui",
3-
"version": "2.1.89",
3+
"version": "2.1.90",
44
"type": "module",
55
"description": "Temporal.io UI",
66
"keywords": [

src/lib/utilities/decode-payload.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ export function decodePayload(
3434
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3535
): Payload | Record<any, any> | string {
3636
const encoding = atob(String(payload?.metadata?.encoding ?? ''));
37+
3738
// Help users out with an english encoding
3839
(payload.metadata.encodingDecoded as unknown as string) = encoding;
3940

40-
if (encoding.startsWith('json/')) {
41+
if (encoding?.startsWith('json/')) {
4142
try {
42-
return parseWithBigInt(atob(String(payload.data)));
43+
return parseWithBigInt(atob(String(payload?.data ?? '')));
4344
} catch (_e) {
4445
// Couldn't correctly decode this just let the user deal with the data as is
4546
}
@@ -119,7 +120,7 @@ export const decodeAllPotentialPayloadsWithCodec = async (
119120
JSONPayload = payloads.map(decodePayload);
120121
}
121122
anyAttributes[key] = JSONPayload;
122-
} else if (key === 'encodedAttributes') {
123+
} else if (key === 'encodedAttributes' && anyAttributes[key]) {
123124
// Can expand if more fields have single payload
124125
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125126
let JSONPayload: string | Payload | Record<any, any>;
@@ -175,7 +176,7 @@ export const decodeAllPotentialPayloadsWithWebsockets = async (
175176
JSONPayload = payloads.map(decodePayload);
176177
}
177178
anyAttributes[key] = JSONPayload;
178-
} else if (key === 'encodedAttributes') {
179+
} else if (key === 'encodedAttributes' && anyAttributes[key]) {
179180
// Can expand if more fields have single payload
180181
// eslint-disable-next-line @typescript-eslint/no-explicit-any
181182
let JSONPayload: string | Payload | Record<any, any>;

0 commit comments

Comments
 (0)