Skip to content

Commit

Permalink
Added request body to parameters of ACL context extraction custom fun…
Browse files Browse the repository at this point in the history
…ction (#412)
  • Loading branch information
epessina authored Oct 24, 2024
1 parent 1b9b0bb commit 701a883
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

### Changed

- Added request body to parameters of ACL context extraction custom function

## [3.3.0] - 2024-10-14

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/lib/extract-acl-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const extractAclContext = async (
): Promise<string[]> => {
if (config.ACL_CONTEXT_BUILDER !== undefined) {
const aclContext = await config.ACL_CONTEXT_BUILDER({
body: request.body,
headers: request.headers,
method: request.method,
pathParams: request.params,
Expand All @@ -46,7 +47,7 @@ export const extractAclContext = async (
? aclContext.filter(element => typeof element === 'string')
: []
}
// todo

// @ts-expect-error this is a decorated request
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const groups = request.getGroups() as string[]
Expand Down
4 changes: 4 additions & 0 deletions src/sdk/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { QuickJSContext } from 'quickjs-emscripten'
import { newAsyncRuntime } from 'quickjs-emscripten'

export interface AclContextBuilderInput {
body?: unknown
headers: Record<string, string | string[] | undefined>
method: string
pathParams: unknown
Expand Down Expand Up @@ -45,6 +46,7 @@ class Sandbox {
if (cachedValue !== undefined) {
return cachedValue
}

/* Follows an alternative if sandbox is too slow
const script = `data:text/javascript;base64,${Buffer.from(CODE).toString('base64')}`
const module = await import(script)
Expand All @@ -63,9 +65,11 @@ class Sandbox {
const error = context.dump(wrappedResult.error) as { message?: string }
throw new Error(`External ACL context builder failed: ${error.message}`)
}

context.unwrapResult(wrappedResult).dispose()
const result = context.getProp(context.global, 'result').consume(context.dump.bind(context)) as string[]
this.cache[hash] = result

return result
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/sdk/test/sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Sandbox', () => {

it('Scripts throws error', async () => {
const input: AclContextBuilderInput = {
body: {},
// @ts-expect-error needed for test
headers: undefined,
method: 'GET',
Expand All @@ -43,6 +44,7 @@ describe('Sandbox', () => {

it('Eval ACL context builder', async () => {
const input: AclContextBuilderInput = {
body: {},
headers: {
userproperties: 'property',
},
Expand Down

0 comments on commit 701a883

Please sign in to comment.