Skip to content

Commit 73ee68a

Browse files
committed
fix: add permission checks for record creation and validate backend-only columns
AdminForth/1731/security-audit
1 parent b083b6a commit 73ee68a

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AdminForthPlugin } from "adminforth";
1+
import { ActionCheckSource, AdminForthPlugin, interpretResource } from "adminforth";
22
import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource } from "adminforth";
33
import type { PluginOptions } from './types.js';
44

@@ -72,8 +72,22 @@ export default class InlineCreatePlugin extends AdminForthPlugin {
7272
if ( this.resourceConfig.resourceId !== resourceId) {
7373
return { error: 'Resource ID mismatch' };
7474
}
75+
7576
const resource = this.adminforth.config.resources.find(r => r.resourceId === resourceId);
76-
77+
78+
const { allowedActions } = await interpretResource(adminUser, resource, {}, ActionCheckSource.DisplayButtons, this.adminforth);
79+
if (!allowedActions.create) {
80+
return { error: 'User does not have permission to create records for this resource' };
81+
}
82+
83+
for (const column of resource.columns) {
84+
if (column.backendOnly) {
85+
if (record[column.name] !== undefined) {
86+
return { error: `Column "${column.name}" is backend-only and cannot be set by the user` };
87+
}
88+
};
89+
}
90+
7791
const cleanRecord = resource.columns.reduce((acc, field) => {
7892
if (record[field.name] !== undefined && record[field.name] !== null) {
7993
acc[field.name] = record[field.name];

0 commit comments

Comments
 (0)