Skip to content

Commit 8aa8459

Browse files
NextJS API: Removed support for dev-only GET requests.
1 parent 660bade commit 8aa8459

File tree

14 files changed

+17
-59
lines changed

14 files changed

+17
-59
lines changed

src/packages/next/lib/api/get-params.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,14 @@
11
import type { Request } from "express";
22

3-
export default function getParams(
4-
req: Request,
5-
{ allowGet }: { allowGet?: boolean } = {}
6-
): { [param: string]: any } {
3+
export default function getParams(req: Request): { [param: string]: any } {
74
if (req?.method == "POST") {
85
return new Proxy(
96
{},
107
{
118
get(_, key) {
129
return req.body?.[key];
1310
},
14-
}
15-
);
16-
} else if (allowGet && req?.method == "GET") {
17-
// allowGet is NOT enabled by default, since this could lead to a sneaky click on a link attack.
18-
// Should only be enabled for dev purposes or for specific endpoints where making the api call
19-
// doesn't potential leak private information.
20-
return new Proxy(
21-
{},
22-
{
23-
get(_, key) {
24-
if (typeof key != "string") {
25-
return undefined;
26-
}
27-
return req.query?.[key];
28-
},
29-
}
11+
},
3012
);
3113
} else {
3214
// only support params for POST requests.

src/packages/next/pages/api/v2/compute/get-images-google.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ async function get(req) {
2727
if (!account_id) {
2828
throw Error("must be signed in");
2929
}
30-
let { noCache } = getParams(req, {
31-
allowGet: true,
32-
});
30+
let { noCache } = getParams(req);
3331
if (noCache) {
3432
// NOTE: only admins can specify noCache
3533
if (!(await userIsInGroup(account_id, "admin"))) {

src/packages/next/pages/api/v2/compute/get-images.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ async function get(req) {
2727
if (!account_id) {
2828
throw Error("must be signed in");
2929
}
30-
let { noCache } = getParams(req, {
31-
allowGet: true,
32-
});
30+
let { noCache } = getParams(req);
3331
if (noCache) {
3432
// NOTE: only admins can specify noCache
3533
if (!(await userIsInGroup(account_id, "admin"))) {

src/packages/next/pages/api/v2/compute/get-log.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ async function get(req) {
2626
if (!account_id) {
2727
throw Error("must be signed in");
2828
}
29-
const { id } = getParams(req, {
30-
allowGet: true,
31-
});
29+
const { id } = getParams(req);
3230
return await getEventLog({ id, account_id });
3331
}
3432

src/packages/next/pages/api/v2/compute/get-serial-port-output.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ async function get(req) {
3131
throw Error("user must be signed in");
3232
}
3333
// id of the server
34-
const { id } = getParams(req, {
35-
allowGet: true,
36-
});
34+
const { id } = getParams(req);
3735
const server = await getServerNoCheck(id);
3836

3937
if (

src/packages/next/pages/api/v2/compute/get-server-title.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ async function get(req) {
2626
if (!account_id) {
2727
throw Error("must be signed in");
2828
}
29-
const { id } = getParams(req, {
30-
allowGet: true,
31-
});
29+
const { id } = getParams(req);
3230
return await getTitle({ id, account_id });
3331
}
3432

src/packages/next/pages/api/v2/compute/get-servers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ async function get(req) {
2626
if (!account_id) {
2727
throw Error("must be signed in");
2828
}
29-
const { project_id, id } = getParams(req, {
30-
allowGet: true,
31-
});
29+
const { project_id, id } = getParams(req);
3230
return await getServers({
3331
account_id,
3432
project_id,

src/packages/next/pages/api/v2/compute/scripts.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import {
1111
getStopScript,
1212
getDeprovisionScript,
1313
} from "@cocalc/server/compute/control";
14-
import {
15-
getAccountWithApiKey as getProjectIdWithApiKey,
16-
} from "@cocalc/server/api/manage";
14+
import { getAccountWithApiKey as getProjectIdWithApiKey } from "@cocalc/server/api/manage";
1715
import getParams from "lib/api/get-params";
1816
import getPool from "@cocalc/database/pool";
1917

@@ -23,7 +21,6 @@ import {
2321
ComputeServerScriptsOutputSchema,
2422
} from "lib/api/schema/compute/scripts";
2523

26-
2724
async function handle(req, res) {
2825
try {
2926
res.send(await get(req));
@@ -34,7 +31,7 @@ async function handle(req, res) {
3431
}
3532

3633
export async function get(req) {
37-
const { api_key, id: id0, action } = getParams(req, { allowGet: true });
34+
const { api_key, id: id0, action } = getParams(req);
3835
// use api_key to get project, and also verify access:
3936
const id = parseInt(id0);
4037
return await getScript({ api_key, id, action });
@@ -85,7 +82,7 @@ export default apiRoute({
8582
scripts: apiRouteOperation({
8683
method: "POST",
8784
openApiOperation: {
88-
tags: ["Compute"]
85+
tags: ["Compute"],
8986
},
9087
})
9188
.input({

src/packages/next/pages/api/v2/jupyter/execute.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export default async function handle(req, res) {
3737

3838
async function doIt(req) {
3939
const { input, kernel, history, tag, noCache, hash, project_id, path } =
40-
getParams(req, {
41-
allowGet: true,
42-
});
40+
getParams(req);
4341
const account_id = await getAccountId(req);
4442
const analytics_cookie = req.cookies[analytics_cookie_name];
4543
return await execute({

src/packages/next/pages/api/v2/jupyter/kernels.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import getParams from "lib/api/get-params";
1010
import getAccountId from "lib/account/get-account";
1111

1212
export default async function handle(req, res) {
13-
const { project_id } = getParams(req, {
14-
allowGet: true,
15-
});
13+
const { project_id } = getParams(req);
1614
const account_id = project_id != null ? await getAccountId(req) : undefined;
1715
try {
1816
res.json({

0 commit comments

Comments
 (0)