Skip to content

Commit 0605fcf

Browse files
fix(logs): enforce unique PII rule scope server-side
The contract accepted multiple rules with the same workspaceId (or several null all-rules); resolution is first-match, so duplicates could disagree with the UI. Add a schema refine rejecting duplicate scopes.
1 parent 7313e18 commit 0605fcf

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

apps/sim/lib/api/contracts/primitives.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,26 @@ export const piiRedactionRuleSchema = z.object({
9797

9898
export type PiiRedactionRule = z.output<typeof piiRedactionRuleSchema>
9999

100-
/** Enterprise PII redaction policy applied to workflow logs on persist. */
100+
/**
101+
* Enterprise PII redaction policy applied to workflow logs on persist. Each
102+
* scope is unique: at most one all-workspaces rule (`workspaceId: null`) and at
103+
* most one rule per workspace — resolution is most-specific-wins, so duplicate
104+
* scopes would make masking depend on array order.
105+
*/
101106
export const piiRedactionSettingsSchema = z.object({
102-
rules: z.array(piiRedactionRuleSchema).max(1000),
107+
rules: z
108+
.array(piiRedactionRuleSchema)
109+
.max(1000)
110+
.refine(
111+
(rules) => {
112+
const scopes = rules.map((r) => r.workspaceId ?? '__all__')
113+
return new Set(scopes).size === scopes.length
114+
},
115+
{
116+
message:
117+
'Each workspace (and the all-workspaces default) may have at most one PII redaction rule.',
118+
}
119+
),
103120
})
104121

105122
export type PiiRedactionSettings = z.output<typeof piiRedactionSettingsSchema>

0 commit comments

Comments
 (0)