Skip to content

Commit

Permalink
feat: safely log url
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <[email protected]>
  • Loading branch information
setchy committed Oct 4, 2023
1 parent cf2d442 commit 67dc171
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import fs from "node:fs";
import path from "node:path";
import { createBom, submitBom } from "./index.js";
import compression from "compression";
import { URL } from "url";

// Timeout milliseconds. Default 10 mins
const TIMEOUT_MS =
Expand All @@ -24,10 +25,19 @@ app.use(
app.use(compression());

const gitClone = (repoUrl) => {
const parsedUrl = new URL(repoUrl);

const userInfo =
parsedUrl.username && parsedUrl.password
? `${parsedUrl.username}:*****`
: parsedUrl.username || "";

const sanitizedRepoUrl = `${parsedUrl.protocol}//${userInfo}${parsedUrl.host}${parsedUrl.pathname}`;

const tempDir = fs.mkdtempSync(
path.join(os.tmpdir(), path.basename(repoUrl))
);
console.log("Cloning", repoUrl, "to", tempDir);
console.log("Cloning", sanitizedRepoUrl, "to", tempDir);
const result = spawnSync("git", ["clone", repoUrl, "--depth", "1", tempDir], {
encoding: "utf-8",
shell: false
Expand Down

0 comments on commit 67dc171

Please sign in to comment.