Skip to content

Commit 1827913

Browse files
committed
Fix tar authentication
It was checking the request path but for tars the path is in the query variable so the request path is irrelevant.
1 parent 624cd9d commit 1827913

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/node/routes/static.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,33 @@ import * as tarFs from "tar-fs"
77
import * as zlib from "zlib"
88
import { HttpCode, HttpError } from "../../common/http"
99
import { rootPath } from "../constants"
10-
import { authenticated, replaceTemplates } from "../http"
10+
import { authenticated, ensureAuthenticated, replaceTemplates } from "../http"
1111
import { getMediaMime, pathToFsPath } from "../util"
1212

1313
export const router = Router()
1414

1515
// The commit is for caching.
1616
router.get("/(:commit)(/*)?", async (req, res) => {
17+
// Used by VS Code to load extensions into the web worker.
18+
const tar = Array.isArray(req.query.tar) ? req.query.tar[0] : req.query.tar
19+
if (typeof tar === "string") {
20+
ensureAuthenticated(req)
21+
let stream: Readable = tarFs.pack(pathToFsPath(tar))
22+
if (req.headers["accept-encoding"] && req.headers["accept-encoding"].includes("gzip")) {
23+
logger.debug("gzipping tar", field("path", tar))
24+
const compress = zlib.createGzip()
25+
stream.pipe(compress)
26+
stream.on("error", (error) => compress.destroy(error))
27+
stream.on("close", () => compress.end())
28+
stream = compress
29+
res.header("content-encoding", "gzip")
30+
}
31+
res.set("Content-Type", "application/x-tar")
32+
stream.on("close", () => res.end())
33+
return stream.pipe(res)
34+
}
35+
36+
// If not a tar use the remainder of the path to load the resource.
1737
if (!req.params[0]) {
1838
throw new HttpError("Not Found", HttpCode.NotFound)
1939
}
@@ -32,26 +52,6 @@ router.get("/(:commit)(/*)?", async (req, res) => {
3252
res.header("Cache-Control", "public, max-age=31536000")
3353
}
3454

35-
/**
36-
* Used by VS Code to load extensions into the web worker.
37-
*/
38-
const tar = Array.isArray(req.query.tar) ? req.query.tar[0] : req.query.tar
39-
if (typeof tar === "string") {
40-
let stream: Readable = tarFs.pack(pathToFsPath(tar))
41-
if (req.headers["accept-encoding"] && req.headers["accept-encoding"].includes("gzip")) {
42-
logger.debug("gzipping tar", field("path", resourcePath))
43-
const compress = zlib.createGzip()
44-
stream.pipe(compress)
45-
stream.on("error", (error) => compress.destroy(error))
46-
stream.on("close", () => compress.end())
47-
stream = compress
48-
res.header("content-encoding", "gzip")
49-
}
50-
res.set("Content-Type", "application/x-tar")
51-
stream.on("close", () => res.end())
52-
return stream.pipe(res)
53-
}
54-
5555
res.set("Content-Type", getMediaMime(resourcePath))
5656

5757
if (resourcePath.endsWith("manifest.json")) {

0 commit comments

Comments
 (0)