Conversation
commit: |
|
I can confirm that this is working as expected |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the backend handler’s mutate endpoint to allow write operations when no authenticated user is present, relying on API-key-based authorization instead.
Changes:
- Removes the hard requirement for
mutaterequests to have an authenticated user. - Makes policy creation conditional on the presence of a user context (roles).
Comments suppressed due to low confidence (1)
src/backend/Handler.ts:174
- When
userCtxis absent (API-key auth path),policybecomesundefined, andlocal.request(mutations, policy)will create anEntryTransactionwith its default policy (Policy.ALLOW_ALL). This effectively bypasses all permission checks for API-key requests (previouslyexpectUser()+ role-based policy enforced permissions). If API keys should not be full-admin, pass an explicit restrictive policy (e.g.,await local.createPolicy([])/Policy.ALLOW_NONE) or derive a dedicated API-key role/policy; if they should be full-admin, consider passingPolicy.ALLOW_ALLexplicitly here to make the escalation intentional and auditable.
const user = userCtx?.user
expectJson()
const policy = user && (await local.createPolicy(user.roles))
const mutations = await body
const attempt = async (retry = 0) => {
await local.syncWith(cnx)
const request = await local.request(mutations, policy)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (action === HandleAction.Mutate && request.method === 'POST') { | ||
| const user = expectUser() | ||
| const user = userCtx?.user | ||
| expectJson() | ||
| const policy = await local.createPolicy(user.roles) | ||
| const policy = user && (await local.createPolicy(user.roles)) | ||
| const mutations = await body |
There was a problem hiding this comment.
This change introduces a new auth mode for mutate (API key without a user), but there are no tests covering the permission behavior and expected status codes for this path. Please add handler tests exercising action=mutate with (1) a verified user (policy enforced) and (2) API-key-only auth, asserting the intended permission model (deny by default vs allow-all vs specific role).
|
@copilot write tests for this change |
Agent-Logs-Url: https://github.com/alineacms/alinea/sessions/2898707a-ee55-4c46-a4c3-01d34bb42e55 Co-authored-by: benmerckx <10584189+benmerckx@users.noreply.github.com>
Agent-Logs-Url: https://github.com/alineacms/alinea/sessions/2898707a-ee55-4c46-a4c3-01d34bb42e55 Co-authored-by: benmerckx <10584189+benmerckx@users.noreply.github.com>
Agent-Logs-Url: https://github.com/alineacms/alinea/sessions/2898707a-ee55-4c46-a4c3-01d34bb42e55 Co-authored-by: benmerckx <10584189+benmerckx@users.noreply.github.com>
Added two tests to
|
No description provided.