Skip to content

Commit e76cde9

Browse files
committed
fix(onepassword): accept only add, remove and replace patch operations
1 parent f3c99c3 commit e76cde9

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎apps/sim/lib/internal/onepassword/json-patch.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ describe('prototype paths', () => {
6363
)
6464
expect(isSafeOnePasswordPatch([{ op: 'replace', path: '/title', value: 'ok' }])).toBe(true)
6565
})
66+
67+
it.each(['test', 'copy', 'move', undefined])(
68+
'refuses a %s operation, which would otherwise be applied as a removal',
69+
(op) => {
70+
expect(isSafeOnePasswordPatch([{ op, path: '/title', value: 'keep' }])).toBe(false)
71+
}
72+
)
6673
})

‎apps/sim/lib/internal/onepassword/json-patch.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ function recordValue(value: unknown): Record<string, unknown> | undefined {
1313
/** Path segments that reach an object's prototype instead of its own data. */
1414
const PROTOTYPE_SEGMENTS = new Set(['__proto__', 'prototype', 'constructor'])
1515

16+
/** The operations 1Password's item patch accepts; anything else would be applied as a removal. */
17+
const PATCH_OPS = new Set<unknown>(['add', 'remove', 'replace'])
18+
1619
/**
17-
* Whether every operation's path names only an item's own data. Patches are applied to a plain
18-
* object in this process, so a path through `__proto__` would write onto every object here.
20+
* Whether every operation is one 1Password accepts and its path names only an item's own data.
21+
* Patches are applied to a plain object in this process, so a path through `__proto__` would
22+
* write onto every object here.
1923
*/
2024
export function isSafeOnePasswordPatch(operations: unknown): operations is JsonPatchOperation[] {
2125
return (
2226
Array.isArray(operations) &&
2327
operations.every((operation) => {
24-
const path = recordValue(operation)?.path
28+
const record = recordValue(operation)
29+
const path = record?.path
2530
return (
31+
PATCH_OPS.has(record?.op) &&
2632
typeof path === 'string' &&
2733
path.split('/').every((segment) => !PROTOTYPE_SEGMENTS.has(segment))
2834
)

0 commit comments

Comments
 (0)