Skip to content

Commit d0e573b

Browse files
fix(guardrails): mint internal token per mask request
A single token (5min TTL) could expire mid-batch when a large execution fans out into many sequential chunk requests; mint one per request instead.
1 parent d68546a commit d0e573b

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

apps/sim/lib/guardrails/mask-client.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export async function maskPIIBatchViaHttp(
3232
): Promise<string[]> {
3333
if (texts.length === 0) return []
3434

35-
const token = await generateInternalToken()
3635
const url = `${getInternalApiBaseUrl()}/api/guardrails/mask-batch`
3736

3837
const masked: string[] = []
@@ -41,7 +40,7 @@ export async function maskPIIBatchViaHttp(
4140

4241
const flush = async () => {
4342
if (batch.length === 0) return
44-
const out = await postChunk(url, token, batch, entityTypes, language)
43+
const out = await postChunk(url, batch, entityTypes, language)
4544
if (out.length !== batch.length) {
4645
throw new Error('PII mask-batch returned an unexpected result')
4746
}
@@ -68,11 +67,14 @@ export async function maskPIIBatchViaHttp(
6867

6968
async function postChunk(
7069
url: string,
71-
token: string,
7270
texts: string[],
7371
entityTypes: string[],
7472
language: string | undefined
7573
): Promise<string[]> {
74+
// Mint per request: a single token (5min TTL) can expire mid-batch when a
75+
// large execution fans out into many sequential chunk requests.
76+
const token = await generateInternalToken()
77+
7678
// boundary-raw-fetch: internal server-to-server call to the app container (internal JWT auth, configurable base URL)
7779
const response = await fetch(url, {
7880
method: 'POST',

0 commit comments

Comments
 (0)