@cosmicdrift/kumiko-guards 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/_lib/git-env.ts +22 -0
- package/src/_lib/roots.ts +1 -18
- package/src/changes.json +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-guards",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "AST-based security guards for Kumiko repos: direct-fs/fetch, tenant escalation, admin-API, escape hatches and related checks, run over a shared ts-morph project.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawned git calls get an allowlisted environment, never `...process.env`.
|
|
3
|
+
* A caller running as a pre-push hook would otherwise inherit `GIT_DIR`/
|
|
4
|
+
* `GIT_WORK_TREE` from git, which git prefers over `cwd` — so an inherited
|
|
5
|
+
* environment would answer for the hook's repo instead of the path being
|
|
6
|
+
* asked about. `HOME` stays in, so the global config is still read.
|
|
7
|
+
*
|
|
8
|
+
* An allowlist (not a blocklist) so a future git env var neither of us has
|
|
9
|
+
* thought of yet is excluded by construction, not by omission.
|
|
10
|
+
*/
|
|
11
|
+
export const GIT_ENV_KEYS = ["PATH", "HOME", "TMPDIR", "TMP", "TEMP", "USER", "LOGNAME"] as const;
|
|
12
|
+
|
|
13
|
+
export function gitEnv(
|
|
14
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
15
|
+
): Record<string, string> {
|
|
16
|
+
const out: Record<string, string> = {};
|
|
17
|
+
for (const key of GIT_ENV_KEYS) {
|
|
18
|
+
const value = env[key];
|
|
19
|
+
if (value !== undefined) out[key] = value;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
package/src/_lib/roots.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
RepoManifestError,
|
|
19
19
|
type RepoManifestSource,
|
|
20
20
|
} from "@cosmicdrift/kumiko-repo-manifest";
|
|
21
|
+
import { gitEnv } from "./git-env";
|
|
21
22
|
|
|
22
23
|
export type { RepoKind } from "@cosmicdrift/kumiko-repo-manifest";
|
|
23
24
|
|
|
@@ -69,24 +70,6 @@ function manifestAt(dir: string): LoadedRepoManifest | undefined {
|
|
|
69
70
|
return result;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
/**
|
|
73
|
-
* Spawned git calls get an allowlisted environment, never `...process.env`.
|
|
74
|
-
* A caller running as a pre-push hook would otherwise inherit `GIT_DIR`/
|
|
75
|
-
* `GIT_WORK_TREE` from git, which git prefers over `cwd` — so an inherited
|
|
76
|
-
* environment would answer for the hook's repo instead of the path being
|
|
77
|
-
* asked about. `HOME` stays in, so the global config is still read.
|
|
78
|
-
*/
|
|
79
|
-
const GIT_ENV_KEYS = ["PATH", "HOME", "TMPDIR", "TMP", "TEMP", "USER", "LOGNAME"] as const;
|
|
80
|
-
|
|
81
|
-
function gitEnv(): Record<string, string> {
|
|
82
|
-
const env: Record<string, string> = {};
|
|
83
|
-
for (const key of GIT_ENV_KEYS) {
|
|
84
|
-
const value = process.env[key];
|
|
85
|
-
if (value !== undefined) env[key] = value;
|
|
86
|
-
}
|
|
87
|
-
return env;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
73
|
function git(from: string, args: readonly string[]): string | undefined {
|
|
91
74
|
if (!existsSync(from)) return undefined;
|
|
92
75
|
try {
|
package/src/changes.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Spawned git calls no longer inherit GIT_DIR/GIT_WORK_TREE",
|
|
6
|
+
"detail": "Guards that shell out to git now pass an allowlisted environment. Running inside a Husky pre-push hook, an inherited GIT_DIR pointed git at the hook's repo instead of the path being checked, so a guard could read and write the wrong repository."
|
|
7
|
+
}
|
|
8
|
+
]
|