Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runql.ai.source": "githubCopilot",
"runql.ai.extension": "",
"runql.ai.apiProvider": "",
"runql.ai.model": "gpt-4.1",
"runql.ai.apiBaseUrl": "",
"runql.ai.sendSchemaContext": true,
"runql.ai.maxSchemaChars": 150000
}
11 changes: 10 additions & 1 deletion src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("planted API bugs", () => {
test.fails("rejects inactive keys", () => {
expect(authenticate("revoked-token")).toBeNull();
});
test.fails("does not trust admin role from body", async () => {
test("does not trust admin role from body", async () => {
const app = buildApp();
const res = await app.inject({
method: "POST",
Expand All @@ -14,6 +14,15 @@ describe("planted API bugs", () => {
});
expect(res.json().ok).toBe(false);
});
test("does not trust alternative admin flags in body", async () => {
const app = buildApp();
const res = await app.inject({
method: "POST",
url: "/api/admin/users",
payload: { isAdmin: true, Role: "admin", roles: ["admin"], name: "Alice" },
});
expect(res.json().ok).toBe(false);
});
test("server responds", async () => {
const app = buildApp();
const res = await app.inject({ method: "POST", url: "/api/tokens" });
Expand Down
9 changes: 7 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const configSchema = z.object({
name: z.string(),
config: z.object({ retries: z.number().optional() }).strip(),
});
const userPayloadSchema = z
.object({
name: z.string().optional(),
email: z.string().optional(),
})
.strip();
export function buildApp() {
const app = Fastify();
app.setErrorHandler((err: Error, _, reply) =>
Expand All @@ -16,8 +22,7 @@ export function buildApp() {
requireAuth(req.headers.authorization?.replace("Bearer ", "")),
);
app.post("/api/admin/users", async (req) => {
const body = req.body as any;
if (body.role === "admin") return { ok: true, granted: "admin" };
const body = userPayloadSchema.parse(req.body ?? {});
return { ok: false };
});
app.post("/api/webhooks/retry", async (req) => {
Expand Down