Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F8929111
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/http/match-policy.ts b/src/http/match-policy.ts
new file mode 100644
index 00000000..65f7652c
--- /dev/null
+++ b/src/http/match-policy.ts
@@ -0,0 +1,18 @@
+import { Middleware } from "koa";
+import Policy from "../chip-types/policy";
+
+export default function MatchPolicy(policy: Policy): Middleware {
+ return async function (ctx, next) {
+ const result = await policy.check(ctx.$context);
+ if (!result) {
+ ctx.body = "Not allowed";
+ ctx.status = 403;
+ return;
+ }
+ if (!result.allowed) {
+ ctx.body = result.reason;
+ ctx.status = 403;
+ }
+ await next();
+ };
+}
diff --git a/src/http/middlewares.ts b/src/http/middlewares.ts
index 10cb823a..47d34175 100644
--- a/src/http/middlewares.ts
+++ b/src/http/middlewares.ts
@@ -1,4 +1,5 @@
import { default as extractContext } from "./extract-context";
import { default as parseBody } from "./parse-body";
+import { default as MatchPolicy } from "./match-policy";
-export default { extractContext, parseBody };
+export default { extractContext, parseBody, MatchPolicy };
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Sep 20, 21:40 (7 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
949705
Default Alt Text
(1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment