Initial commit - full huishou project

This commit is contained in:
jiapengyu
2026-07-27 14:07:26 +08:00
commit 60790ad1b3
39127 changed files with 5989265 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
import type { ParsedArgv } from './parse-argv.types';
/**
* Parse the tokens that would be forwarded to a `git` child-process and
* return a structured summary of what the invocation does.
*/
export declare function parseArgv(...tokens: readonly unknown[]): ParsedArgv;
@@ -0,0 +1,59 @@
import type { Vulnerability } from '../vulnerabilities/vulnerability.types';
/** Where a config value originates / which scope it targets. */
export type ConfigScope = 'inline' | 'env' | 'local' | 'global' | 'system' | 'worktree' | 'file';
/** A single flag or option found in the token list. */
export interface ParsedFlag {
/** Canonical name: e.g. `'-m'`, `'--amend'`, `'--no-verify'`. */
name: string;
/** Value consumed by this flag, when applicable. */
value?: string;
}
/** A config key that this invocation reads via `git config`. */
export interface ConfigRead {
/** Lower-cased dotted key, e.g. `'user.name'`. */
key: string;
scope: ConfigScope;
}
/** A config key that this invocation writes. */
export interface ConfigWrite extends ConfigRead {
/**
* The value being written.
* Absent for delete-style operations (`--unset`, `--remove-section`).
* For `scope: 'env'` this is the environment-variable *name*, not the
* resolved config value.
*/
value?: string;
}
export interface ParsedConfigActivity {
/** Config keys read by a `git config` read operation. */
read: ConfigRead[];
/** Config keys written by this invocation (inline overrides and `git config` writes). */
write: ConfigWrite[];
}
/**
* Fully parsed representation of a set of varargs to be passed into the `git` child process.
*/
export interface ParsedArgv {
/**
* The git sub-command, e.g. `'commit'`, `'push'`.
* `null` when the list contains only global flags (`['--version']`, `[]`).
*/
task: string | null;
/**
* Every flag and option in the tokens (global + command-level), with
* combined short clusters expanded: `-uc` → `[{name:'-u'}, {name:'-c'}]`.
*/
flags: ParsedFlag[];
/**
* File-system paths: tokens after `--`, or `pathspec()` wrapper objects.
* */
paths: string[];
/**
* Activities being requested for the `git` config
*/
config: ParsedConfigActivity;
/**
* Attack vectors discovered in the arguments
*/
readonly vulnerabilities: Vulnerability[];
}
@@ -0,0 +1,3 @@
import type { ParsedConfigActivity } from '../args/parse-argv.types';
import { type Flag } from '../flags/flags.helpers';
export declare function collectConfigAccess(task: string | null, flags: Flag[], positionals: string[]): ParsedConfigActivity;
@@ -0,0 +1,4 @@
export declare const CONFIG_WRITE_FLAGS: Set<string>;
export declare const CONFIG_READ_FLAGS: Set<string>;
export declare const CONFIG_WRITE_VERBS: Set<string>;
export declare const CONFIG_READ_VERBS: Set<string>;
@@ -0,0 +1,6 @@
export interface ConfigOperation {
isWrite: boolean;
isRead: boolean;
key: string;
value?: string;
}
@@ -0,0 +1,13 @@
import type { ConfigScope } from '../args/parse-argv.types';
import { type Flag } from '../flags/flags.helpers';
import type { ConfigOperation } from './config.types';
export declare function detectConfigAction(flags: Flag[], positionals: string[]): ConfigOperation | null;
export declare function toOperation(scope: ConfigScope, operation: ConfigOperation): {
key: string;
value: string;
scope: ConfigScope;
} | {
key: string;
scope: ConfigScope;
value?: undefined;
};
+6
View File
@@ -0,0 +1,6 @@
import type { ParsedConfigActivity } from '../args/parse-argv.types';
import type { Vulnerability } from '../vulnerabilities/vulnerability.types';
export declare function parseEnv(raw: Record<string, unknown>): {
config: ParsedConfigActivity;
vulnerabilities: Vulnerability[];
};
@@ -0,0 +1,9 @@
export interface Flag {
name: string;
value?: string;
/** Value came from the next token rather than being embedded after `=`. */
absorbedNext: boolean;
/** Switch appeared before the git sub-command. */
isGlobal: boolean;
}
export declare function scopedFlags(flags: Flag[], scope: 'global' | 'task'): Generator<Flag, void, unknown>;
@@ -0,0 +1,6 @@
import type { Flag } from './flags.helpers';
export interface GlobalFlags {
flags: Flag[];
taskIndex: number;
}
export declare function parseGlobalFlags(tokens: readonly unknown[], flags?: Flag[]): GlobalFlags;
@@ -0,0 +1,8 @@
import type { Flag } from './flags.helpers';
type TaskFlags = {
flags: Flag[];
positionals: string[];
pathspecs: string[];
};
export declare function parseTaskFlags(tokens: readonly unknown[], task: string | null, flags?: Flag[]): TaskFlags;
export {};
+9
View File
@@ -0,0 +1,9 @@
export interface FlagSpec {
readonly short: ReadonlyMap<string, boolean>;
readonly long: ReadonlySet<string>;
}
export declare const GLOBAL: FlagSpec;
export declare function getFlagSpecForTask(task?: string | null): {
short: Map<string, boolean>;
long: ReadonlySet<string>;
};
@@ -0,0 +1,7 @@
/** Parse a single raw token (e.g. `'-m'`, `'--amend'`, `'-uc'`) into one or
* more switch descriptors. Values are not yet resolved for needsNext=true. */
export declare function expandToken(raw: string, spec?: import("./flag-specs").FlagSpec): Array<{
name: string;
value?: string;
needsNext: boolean;
}>;
@@ -0,0 +1,3 @@
import type { ParsedConfigActivity } from '../args/parse-argv.types';
import type { Vulnerability } from './vulnerability.types';
export declare function detectVulnerableConfigWrites({ write, }: ParsedConfigActivity): Generator<Vulnerability>;
@@ -0,0 +1,3 @@
import type { Flag } from '../flags/flags.helpers';
import type { Vulnerability } from './vulnerability.types';
export declare function detectVulnerableFlags(task: null | string, flags: Flag[]): Generator<Vulnerability>;
@@ -0,0 +1,4 @@
import type { ParsedConfigActivity } from '../args/parse-argv.types';
import type { Flag } from '../flags/flags.helpers';
import type { Vulnerability } from './vulnerability.types';
export declare function vulnerabilityAnalysis(task: null | string, flags: Flag[], config: ParsedConfigActivity): Vulnerability[];
@@ -0,0 +1,5 @@
/**
* Retrieves just the vulnerabilities identified in the supplied varargs tokens
* and environment variables.
*/
export declare function vulnerabilityCheck(tokens: readonly string[], env: Record<string, unknown>): import("./vulnerability.types").Vulnerability[];
@@ -0,0 +1,104 @@
export type VulnerabilityCategory = keyof VulnerabilityCategoryFlags;
export interface Vulnerability {
category: VulnerabilityCategory;
message: string;
}
export interface VulnerabilityCategoryFlags {
/**
* Use of the `alias.*` configuration settings in simple-git tasks
*/
allowUnsafeAlias: boolean;
/**
* Use of the `core.askPass` configuration setting and environment variables in simple-git tasks
*/
allowUnsafeAskPass: boolean;
/**
* Allows using environment variables to set configuration paths in simple-git tasks
*/
allowUnsafeConfigPaths: boolean;
/**
* Allows setting configuration fields from environment variables in simple-git tasks. Any
* configuration set in this way will still be subject to the same block-listing checks and
* may require other unsafe flags to be enabled for use.
*/
allowUnsafeConfigEnvCount: boolean;
/**
* Allows setting credential helper in simple-git tasks
*/
allowUnsafeCredentialHelper: boolean;
/**
* Allows setting path to the text editor utility in simple-git tasks
*/
allowUnsafeEditor: boolean;
/**
* Allows use of setting paths for merge tools in simple-git tasks
*/
allowUnsafeMergeDriver: boolean;
/**
* Allows setting path to the pager utility in simple-git tasks
*/
allowUnsafePager: boolean;
/**
* By default, `simple-git` prevents the use of inline configuration
* options to override the protocols available for the `git` child
* process to prevent accidental security vulnerabilities when
* unsanitised user data is passed directly into operations such as
* `git.addRemote`, `git.clone` or `git.raw`.
*
* Enable this override to use the `ext::` protocol (see examples on
* [git-scm.com](https://git-scm.com/docs/git-remote-ext#_examples)).
*/
allowUnsafeProtocolOverride: boolean;
/**
* Given the possibility of using `--upload-pack` and `--receive-pack` as
* attack vectors, the use of these in any command (or the shorthand
* `-u` option in a `clone` operation) are blocked by default.
*
* Enable this override to permit the use of these arguments.
*/
allowUnsafePack: boolean;
/**
* Using a `-c` switch to enable custom SSH commands opens up a potential
* attack vector for running arbitrary commands.
*/
allowUnsafeSshCommand: boolean;
/**
* Using a `-c` switch to enable custom proxy command for the `git://` transport
* exposes and attack vector for running arbitrary commands.
*/
allowUnsafeGitProxy: boolean;
/**
* Using a `-c` switch to enable custom hooks path commands to be run automatically
* exposes and attack vector for running arbitrary commands.
*/
allowUnsafeHooksPath: boolean;
/**
* Using a `-c` switch to enable setting binary for processing diffs
* exposes and attack vector for running arbitrary commands.
*/
allowUnsafeDiffExternal: boolean;
/**
* Using a `-c` switch to enable setting binary for retrieving text content of a file
*/
allowUnsafeDiffTextConv: boolean;
/**
* Using a `-c` switch to enable setting binary for `smudge` and `clean` operations
* which can add and remove content to a file during checkout and commit.
*/
allowUnsafeFilter: boolean;
/**
* Using a `-c` switch to enable setting the binary to which `git` will delegate
* file content change detection.
*/
allowUnsafeFsMonitor: boolean;
/**
* Using a `-c` switch to configure the GPG signing program (`gpg.program`) or a
* per-format variant (`gpg.ssh.program`, `gpg.x509.program`). Controlling the signing
* binary allows an attacker to run arbitrary code whenever a commit or tag is signed.
*/
allowUnsafeGpgProgram: boolean;
/**
* Allows overriding template directory either by environment variable or configuration in simple-git tasks
*/
allowUnsafeTemplateDir: boolean;
}