Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,14 @@ export async function getAclCtx(env, org, users, key, api) {
};
}

const props = await env.DA_CONFIG?.get(org, { type: 'json' });
let props;
try {
props = await env.DA_CONFIG?.get(org, { type: 'json' });
} catch {
// KV rejects keys longer than 512 bytes (e.g. IMS auth fragments leaking into the URL path).
// Treat as no config found — deny all access rather than propagating a 500.
return { pathLookup, actionSet: new Set() };
}

if (props && props[':type'] === 'sheet' && props[':sheetname'] === 'permissions') {
// It's a single-sheet, move the data to the right place
Expand Down
20 changes: 20 additions & 0 deletions test/utils/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,26 @@ describe('DA auth', () => {
users, org: 'test', aclCtx, key: '',
}, '/some/deep/path', 'write'));
});

it('returns empty action set when DA_CONFIG KV GET throws 414 key-too-long error', async () => {
// IMS auth redirect fragments (access_token=..., ld_hash=...) leak into the URL path,
// producing an org segment >512 bytes. KV rejects the lookup with a 414 error;
// without a guard this unhandled exception propagates to a 500 response.
const longOrg = 'a'.repeat(513);
const kv414Error = new Error(
`KV GET failed: 414 UTF-8 encoded length of ${longOrg.length} exceeds key length limit of 512.`,
);
const failEnv = {
DA_CONFIG: {
get: () => {
throw kv414Error;
},
},
};
const users = [{ email: 'user@example.com' }];
const aclCtx = await getAclCtx(failEnv, longOrg, users, '/test');
assert.strictEqual(aclCtx.actionSet.size, 0, 'oversized org name must produce empty action set, not throw');
});
});

describe('persmissions single sheet', () => {
Expand Down
Loading