Skip to content

Commit 964df4c

Browse files
authored
Add security policy to block endpoints (#2087)
Fixes OPS-3879.
1 parent 306f5df commit 964df4c

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

packages/server/api/src/app/block-variable/block-variable-module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {
55
import {
66
flowHelper,
77
groupStepOutputsById,
8+
Permission,
89
PrincipalType,
910
} from '@openops/shared';
1011
import { engineRunner } from 'server-worker';
1112
import { accessTokenManager } from '../authentication/context/access-token-manager';
13+
import { getProjectScopedRoutePolicy } from '../core/security/route-policies/route-security-policy-factory';
1214
import { flowService } from '../flows/flow/flow.service';
1315
import { flowStepTestOutputService } from '../flows/step-test-output/flow-step-test-output.service';
1416

@@ -58,6 +60,10 @@ const blockVariableController: FastifyPluginAsyncTypebox = async (app) => {
5860
const ExecuteVariableRequest = {
5961
config: {
6062
allowedPrincipals: [PrincipalType.USER, PrincipalType.SERVICE],
63+
security: getProjectScopedRoutePolicy({
64+
allowedPrincipals: [PrincipalType.USER, PrincipalType.SERVICE],
65+
permission: Permission.READ_FLOW,
66+
}),
6167
},
6268
schema: {
6369
description:

packages/server/api/src/app/blocks/base-block-module.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import {
2020
ListVersionRequestQuery,
2121
ListVersionsResponse,
2222
OpsEdition,
23+
Permission,
2324
PrincipalType,
2425
PUBLIC_ROUTE_POLICY,
2526
} from '@openops/shared';
2627
import { engineRunner } from 'server-worker';
2728
import { accessTokenManager } from '../authentication/context/access-token-manager';
29+
import { getProjectScopedRoutePolicy } from '../core/security/route-policies/route-security-policy-factory';
2830
import { flagService } from '../flags/flag.service';
2931
import { flowService } from '../flows/flow/flow.service';
3032
import { flowStepTestOutputService } from '../flows/step-test-output/flow-step-test-output.service';
@@ -241,6 +243,10 @@ const ListCategoriesRequest = {
241243
const OptionsBlockRequest = {
242244
config: {
243245
allowedPrincipals: [PrincipalType.USER],
246+
security: getProjectScopedRoutePolicy({
247+
allowedPrincipals: [PrincipalType.USER],
248+
permission: Permission.READ_FLOW,
249+
}),
244250
},
245251
schema: {
246252
operationId: 'Execute Block Properties',
@@ -251,6 +257,11 @@ const OptionsBlockRequest = {
251257
};
252258

253259
const DeleteBlockRequest = {
260+
config: {
261+
security: getProjectScopedRoutePolicy({
262+
allowedPrincipals: [PrincipalType.USER],
263+
}),
264+
},
254265
schema: {
255266
description:
256267
'Delete a custom block from the system. This endpoint permanently removes a block and its associated metadata. This operation cannot be undone and will affect any flows using this block. Use with caution as it may impact existing flows.',

packages/server/api/src/app/blocks/community-block-module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
22
import { BlockMetadataModel } from '@openops/blocks-framework';
33
import { AddBlockRequestBody, PrincipalType } from '@openops/shared';
44
import { StatusCodes } from 'http-status-codes';
5+
import { getProjectScopedRoutePolicy } from '../core/security/route-policies/route-security-policy-factory';
56
import { blockService } from './block-service';
67

78
export const communityBlocksModule: FastifyPluginAsyncTypebox = async (app) => {
@@ -14,6 +15,9 @@ const communityBlocksController: FastifyPluginAsyncTypebox = async (app) => {
1415
{
1516
config: {
1617
allowedPrincipals: [PrincipalType.USER],
18+
security: getProjectScopedRoutePolicy({
19+
allowedPrincipals: [PrincipalType.USER],
20+
}),
1721
},
1822
schema: {
1923
body: AddBlockRequestBody,

0 commit comments

Comments
 (0)