Relay POST /files uploads through the web proxy and peer relay
The direct proxy already forwards every /files method behind the sign-in gate; the peer relay now allows POST /files beside /chat-uploads. Tests cover the name header, body and refusal of other POST targets.
This commit is contained in:
@@ -76,6 +76,22 @@ async function fixture(t) {
|
||||
return;
|
||||
}
|
||||
res.setHeader("Set-Cookie", "do-not-forward=private");
|
||||
if (req.method === "POST") {
|
||||
let body = "";
|
||||
for await (const chunk of req) body += chunk;
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
name,
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
cookie: req.headers.cookie,
|
||||
upload: req.headers["x-pipelines-upload-name"],
|
||||
type: req.headers["content-type"],
|
||||
body,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
req.url.startsWith("/artifacts/") ||
|
||||
req.url.includes("untrusted.svg")
|
||||
@@ -289,6 +305,46 @@ test("browser can authenticate both machines, relay files and keep local credent
|
||||
);
|
||||
});
|
||||
|
||||
test("file uploads relay to the chosen machine's home folder and other POSTs are refused", async (t) => {
|
||||
const f = await fixture(t);
|
||||
await f.register("one", {
|
||||
endpoints: [f.remotes[0]],
|
||||
password: "password-one",
|
||||
});
|
||||
const upload = (path, headers = {}) =>
|
||||
fetch(f.base + `/peers/one${path}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Cookie: f.cookie,
|
||||
"Content-Type": "text/plain",
|
||||
"X-Pipelines-Upload-Name": "notes%20two.txt",
|
||||
...headers,
|
||||
},
|
||||
body: "hello upload",
|
||||
});
|
||||
const reply = await upload("/files?path=%2Fhome%2Fproject");
|
||||
assert.equal(reply.status, 200);
|
||||
assert.equal(reply.headers.get("set-cookie"), null);
|
||||
assert.deepEqual(await reply.json(), {
|
||||
name: "one",
|
||||
method: "POST",
|
||||
url: "/files?path=%2Fhome%2Fproject",
|
||||
cookie: "pipelines_session=remote-one",
|
||||
upload: "notes%20two.txt",
|
||||
type: "text/plain",
|
||||
body: "hello upload",
|
||||
});
|
||||
// The remote never sees a POST the relay does not allow.
|
||||
const before = f.observations.length;
|
||||
assert.equal((await upload("/artifacts/1/2/report.txt")).status, 404);
|
||||
assert.equal((await upload("/discovery")).status, 404);
|
||||
assert.equal(f.observations.length, before);
|
||||
assert.equal(
|
||||
(await upload("/files?path=%2Fhome", { Cookie: await f.login() })).status,
|
||||
401,
|
||||
);
|
||||
});
|
||||
|
||||
test("websocket relay authenticates the chosen machine without forwarding browser Origin", async (t) => {
|
||||
const f = await fixture(t);
|
||||
await f.register("two", {
|
||||
|
||||
Reference in New Issue
Block a user