@namzu/sdk 69.4.0 → 70.0.0
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/CHANGELOG.md +44 -0
- package/dist/authorization/protected-paths.d.ts +24 -6
- package/dist/authorization/protected-paths.d.ts.map +1 -1
- package/dist/authorization/protected-paths.js +37 -9
- package/dist/authorization/protected-paths.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +263 -0
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/connector/web/guarded-fetch.d.ts +30 -0
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +85 -0
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/connector/web/index.d.ts +1 -1
- package/dist/connector/web/index.d.ts.map +1 -1
- package/dist/connector/web/index.js +1 -1
- package/dist/connector/web/index.js.map +1 -1
- package/dist/plugin/common-layout/read.js +2 -2
- package/dist/plugin/common-layout/read.js.map +1 -1
- package/dist/plugin/hook-module/capabilities.d.ts +12 -0
- package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
- package/dist/plugin/hook-module/capabilities.js +82 -10
- package/dist/plugin/hook-module/capabilities.js.map +1 -1
- package/dist/plugin/hook-module/consent.d.ts +11 -0
- package/dist/plugin/hook-module/consent.d.ts.map +1 -1
- package/dist/plugin/hook-module/consent.js +31 -0
- package/dist/plugin/hook-module/consent.js.map +1 -1
- package/dist/plugin/hook-module/host.d.ts.map +1 -1
- package/dist/plugin/hook-module/host.js +69 -23
- package/dist/plugin/hook-module/host.js.map +1 -1
- package/dist/plugin/hook-module/index.d.ts +1 -1
- package/dist/plugin/hook-module/index.d.ts.map +1 -1
- package/dist/plugin/hook-module/index.js +1 -1
- package/dist/plugin/hook-module/index.js.map +1 -1
- package/dist/plugin/hook-module/scan.js +1 -1
- package/dist/plugin/hook-module/scan.js.map +1 -1
- package/dist/plugin/hook-module/worker-source.d.ts +5 -4
- package/dist/plugin/hook-module/worker-source.d.ts.map +1 -1
- package/dist/plugin/hook-module/worker-source.js +198 -28
- package/dist/plugin/hook-module/worker-source.js.map +1 -1
- package/dist/public-runtime.d.ts +3 -3
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +3 -3
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -1
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +1 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +75 -10
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +21 -3
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +35 -19
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/skills/inline-shell-host.d.ts +6 -0
- package/dist/skills/inline-shell-host.d.ts.map +1 -1
- package/dist/skills/inline-shell-host.js +8 -0
- package/dist/skills/inline-shell-host.js.map +1 -1
- package/dist/skills/inline-shell.d.ts +9 -1
- package/dist/skills/inline-shell.d.ts.map +1 -1
- package/dist/skills/inline-shell.js +78 -10
- package/dist/skills/inline-shell.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +2 -0
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/types/permission/index.d.ts +11 -2
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +12 -2
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +7 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/package.json +1 -1
- package/src/authorization/protected-paths.ts +44 -9
- package/src/authorization/shell-lexer.ts +242 -0
- package/src/connector/web/guarded-fetch.ts +92 -0
- package/src/connector/web/index.ts +6 -1
- package/src/plugin/common-layout/read.ts +2 -2
- package/src/plugin/hook-module/capabilities.ts +94 -10
- package/src/plugin/hook-module/consent.ts +36 -0
- package/src/plugin/hook-module/host.ts +72 -21
- package/src/plugin/hook-module/index.ts +2 -0
- package/src/plugin/hook-module/scan.ts +2 -2
- package/src/plugin/hook-module/worker-source.ts +199 -28
- package/src/public-runtime.ts +6 -0
- package/src/public-tools.ts +4 -1
- package/src/runtime/query/executor.ts +74 -7
- package/src/runtime/query/review-policy.ts +42 -13
- package/src/skills/inline-shell-host.ts +16 -0
- package/src/skills/inline-shell.ts +90 -8
- package/src/tools/builtins/skill.ts +2 -0
- package/src/types/permission/index.ts +20 -3
- package/src/types/tool/index.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 70.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- bb87533: Plugin source policy now holds where it used to be bypassed, and plugin downloads refuse the inside of the machine.
|
|
8
|
+
|
|
9
|
+
What changes for you if you use `plugins.blockedMarketplaces`: `*` now blocks every source (it blocked nothing before), a bare host such as `example.com` also covers its subdomains, `*.example.com` is accepted, and a folder or file on this computer can be blocked by path (`*`, `/work/market`, `file:/work/market`). Every address that belongs to a GitHub repository (`codeload.github.com`, `raw.githubusercontent.com`, `api.github.com/repos/...`, `ssh.github.com`, pages and archives under `github.com/owner/repo/...`) reads as that repository. The list is checked on every redirect hop of a download, on installs from a marketplace (a local entry of a blocked marketplace is no longer installable), and against what is already installed: a plugin whose marketplace source is blocked now is not loaded and `plugin enable` refuses it. If a block list you rely on now blocks more than you meant (for example `*` or a bare host), narrow the entry.
|
|
10
|
+
|
|
11
|
+
New managed-file-only settings, dropped from user, project and local files: `plugins.allowedMarketplaces` (the only marketplace sources that may be added, refreshed or installed from; an empty list admits nothing) and `plugins.disableLaunchSources` (`--plugin-dir` and `--mcp-config` exit 64; a `--settings` layer that adds `mcpServers` is refused too; `--strict-mcp-config` alone stays allowed). Unset, nothing changes.
|
|
12
|
+
|
|
13
|
+
Plugin downloads (catalogs and archives) now refuse an address that is, or resolves to, a loopback, private, link-local or cloud metadata address, on the first request and on every redirect; a catalog that points at an internal https server will be refused (exit 77). Git hosts are resolved too: an address (https, ssh or scp form) whose host is `localhost`, an IP literal inside the machine, or a name that resolves to one or cannot be resolved is refused (exit 77), so an internal Git server by name is no longer reachable. Behind a proxy (`HTTPS_PROXY` or `HTTP_PROXY` holding an http or https address, the host not on `NO_PROXY`; `ALL_PROXY` no longer counts) a name this computer cannot resolve is allowed for downloads and https Git, since the proxy resolves it; literal addresses are always refused. The check reads the name once, so it does not stop DNS rebinding. Git no longer reads system or global Git configuration and runs no credential helper (an https repository that needed your credential helper will now be reported as needing sign-in; ssh keys still work), clones from inside the staging folder, and never follows an HTTP redirect (a repository that moved fails until its catalog entry names the new address). The Git configuration switch-off needs Git 2.32 or later. Zip entries with Windows-unsafe names (in plugin, skill and extension archives alike: a skill or extension zip that holds such a name no longer unpacks) (`CON`, `NUL`, `COM1`, a part ending in a dot or space, a colon, composed/decomposed duplicates) are refused on every platform, and an archive is written to disk as it downloads and unpacked one file at a time instead of being held in memory twice.
|
|
14
|
+
|
|
15
|
+
A folder or file install (`plugin install <path>`, and the Desktop host's folder install) is now judged by both lists as a local source, and a plugin installed that way is judged again at load by the path its install manifest records. A git address with a backslash or control character, or whose host differs between the URL parser and Git, is refused.
|
|
16
|
+
|
|
17
|
+
Host names written in Unicode in a block or allow entry now match their punycode form.
|
|
18
|
+
|
|
19
|
+
`@namzu/sdk`: this is a major because the hooks module's `$.http.fetch` is https only (plain http only to loopback in a test option), checks every redirect hop against private addresses after DNS resolution, and drops `Metadata`-style and `Host` request headers. A hook module that used plain `http://` addresses, an internal https host or a `Metadata` or `Host` header must change the address or stop sending the header. New exports `privateAddressProblem` and `proxyConfigured` for callers that do their own fetching.
|
|
20
|
+
|
|
21
|
+
With `plugins.blockedMarketplaces` or `plugins.allowedMarketplaces` set, an installed plugin whose marketplace is not recorded on this computer, or whose record cannot be read, is no longer loaded: it reports that its source cannot be checked. Re-add the marketplace (`plugin marketplace add`) to load it again. A plugin installed from a folder or file is still judged by its own recorded path. With no list set nothing changes.
|
|
22
|
+
|
|
23
|
+
`@namzu/sdk`: a redirect to another origin in the hooks module's `$.http.fetch` now keeps only `Accept`, `Accept-Language`, `Content-Type` and `User-Agent`; any other header, such as a custom `X-Api-Key`, stays on the first origin.
|
|
24
|
+
|
|
25
|
+
### Minor Changes
|
|
26
|
+
|
|
27
|
+
- 89f3ca7: Commands that a skill holds (`!` lines) now answer to the same checks as the model's own `bash` call. In auto mode a command that changes something no longer runs just because the skill's `allowed-tools` covers it, or because a rule allows the whole shell tool: only a command that reads, or one a rule allows by a pattern that names it, runs, and anything else is not run while the skill loads. When the model loaded the skill, that command's place in the text becomes a note asking the model to run it itself, exactly as written, with the `bash` tool (a numbered list when there are several), so the auto-mode reviewer sees the model's own call and the load goes on; a command a rule denies still fails the load. A typed `/name` or headless load has no model to ask, so it fails with a line that says the command is in the skill's file and to run it as a direct call. If you relied on a skill's commands running unreviewed in auto mode, add a narrow `Bash(<command>)` allow rule for them or run them yourself. A typed `/name` skill now judges and runs its commands in the folder the session's shell was left in by an earlier `cd`, not the session's starting folder, so a command that writes `hooks/x` after `cd .git` is refused as the protected path it is. The permission mode is read again right before a command starts, so a switch to plan or strict mode during a hook or sandbox start still stops it. The refusal for a command a rule or the dangerous-command floor sent to review no longer says an allow rule would lift it.
|
|
28
|
+
|
|
29
|
+
`@namzu/sdk` adds `ToolDispatchOptions.handOff` (a call auto mode would review comes back unrun with `data.handedOff` instead of failing), `CLASSIFY_NESTED_REFUSAL`, and `allowedCallTooWide` and `pinBashWorkingDirectory` to its exports, and `nestedCallModeRefusal` takes an optional `ruleTooWide`. A host that runs skill commands itself should pass it, and use the shell's carried folder (`effectiveBashWorkingDirectory`) for its check and its run.
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- 95189f0: Three places that took a yes too easily now ask or refuse. The CLI is a major release because `namzu mcp approve` with no names no longer approves anything off a terminal: a script that ran it bare must pass `--yes` or name the servers. Nothing else is removed and no setting changes; a person who relied on the old behaviour says yes once.
|
|
34
|
+
|
|
35
|
+
A write by the model to a folder a later session loads instructions from is now asked about in every mode, accept-edits included: `.namzu/skills`, `.namzu/agents`, `.namzu/commands`, `.agents/skills` at any level, the project's `skills/` folder, and any file named `SKILL.md`. A skill's hooks run shell commands and its allowed tools are pre-approved, so a skill written without a question was a way to run commands later. To author a skill, approve the write when asked, or use the skill save flow, which has its own confirmation.
|
|
36
|
+
|
|
37
|
+
`namzu mcp approve` with no name now lists every server it would approve, with the environment variables each project server's headers would send, and asks at a terminal. Off a terminal, or with `--format json`, it approves nothing and exits with a usage error unless you name the servers or pass `--yes`. A script that ran `namzu mcp approve` bare should pass `--yes`. Each line also shows a command server's arguments and the environment variables it would receive. `namzu mcp approve` now refuses outright, with or without `--yes` or names, when a running session started it (its marker, or a process above it carrying the marker), and the session's command-line floor refuses a shell command that runs `namzu mcp approve` or `namzu acp --desktop` in every permission mode. These are guards against a model's shell doing it by accident or by an obvious route, not a sandbox: a process that detaches from the session and clears its environment, or a script the command line does not hold, is not seen, so keep a session's shell sandboxed from writing `.mcp.json` if you need a hard boundary. Run the approval in your own terminal.
|
|
38
|
+
|
|
39
|
+
`namzu acp --desktop` answers plugin-install, marketplace, MCP-approval and settings consents from whatever is written to its input, so it now refuses to start in a process a running session started, such as a model's shell. What is checked is the session marker, on the process or on a process above it. The desktop app is unaffected.
|
|
40
|
+
|
|
41
|
+
`namzu plugin install`, `plugin update` and `plugin marketplace add` now refuse `--yes` and `--accept-surface` (exit 64) when a session started the process, with the same wording as `mcp approve`; run them in your own terminal. A preview still works. The `namzu acp --desktop` refusal now says to start it from the app or your own terminal. A person's tmux or screen server first started from inside a session keeps the marker for its later panes, so those panes are refused too; start the server again from a fresh terminal. Nothing a process says about itself (a tmux global entry, TMUX, PATH) clears the marker, because a session can set all of them.
|
|
42
|
+
|
|
43
|
+
- 7026889: Plugin hooks modules and `pre_tool_use` hooks now refuse where they used to let a call through. A hooks module that fails to load (its `register()` throws, or it does not finish loading) used to answer every event with "continue", so a guard that never loaded waved tool calls through; a `PreToolUse` call is now refused with the reason, a skill's shell command is skipped, and a permission request is left to the person. The same holds for a module the scan refuses (a name it does not allow, say): the scan may not have seen which events it hooks, so all three guarding events are answered as a failed guard, not passed, and every tool call of that plugin is refused until the module is fixed or the plugin turned off. A hooks module the CLI cannot start (two modules named, or a data folder overlapping the plugin) is now said as a warning. The host answers a module's `$` calls only for the calls its own scan declared. The trust screen, `namzu plugin validate` and the Desktop plugin view now say a module that hooks `PreToolUse`, `PermissionRequest` or `PreSkillShellCommand` "can approve, deny or change tool calls without asking you", and describe the worker as running "with your permissions" instead of "isolated". The exported `hookModuleConsentLines` and the saved `HookGrant.runs` text are reworded. A module with a top-level `let x;` no longer stops the plugin runtime from starting. Nothing to change on your side; a plugin that relied on a failed module letting calls through now sees the refusal. A hooks module's context now has no `Error.captureStackTrace`, a fixed `Error.prepareStackTrace` and `stackTraceLimit`, none of `WebAssembly`, `WeakRef`, `FinalizationRegistry`, `Atomics`, `SharedArrayBuffer` or `queueMicrotask`, frozen intrinsics, and a failed call on `$` now throws a frozen object with no prototype (`name`, `message`, `stack`, `toString`) instead of an `Error`, so a module that tests `error instanceof Error` on a `$` failure reads `error.message` instead. Every refusal message of a module says to update or fix the plugin, start a new session, or run `namzu plugin disable <name>`. A module can no longer extend built-in prototypes (`Array.prototype.last = ...` throws), and `new Error(...).stack` is an empty string; define helpers as plain functions instead. A failed hook now says "Fix the hook, or turn the plugin off with `namzu plugin disable <name>`" because the module stays loaded.
|
|
44
|
+
- f67678d: A host that sets `screenConsent` and has no prompt to ask now has the first look at the screen refused in `auto` mode too, with the same plain reason it already gave in the other modes. Before, `auto` skipped the consent and a run with nobody to ask could drive the screen unreviewed. A host that passes a prompt is unchanged: `auto` still never asks. To decide the call ahead of time, allow it with a rule.
|
|
45
|
+
- 639ff56: Three shell checks now ask or refuse where they used to let a line through. `let` and `declare -i` (also `typeset -i`, `local -i`, clustered flags such as `-ia`) with an argument that is not a plain number or `NAME=number` are read as opaque, because bash evaluates `a[$(cmd)]` in such an argument and runs `cmd`: a deny rule or escalation check could not see it before, and the line now asks. In a skill or command template, a `$ARGUMENTS`-style value placed right after a bare `$` inside a command (for example `echo $$ARGUMENTS`) is refused, since the quote after the `$` was read by bash as an ANSI-C string and a trailing backslash could end it early. The same holds for a name with a subscript given to `declare`, `typeset`, `local`, `printf -v` or `read`, the operand of `-v` in `test` and `[`, an unknown option after `command` or `builtin` in front of these, and a line that declares a name `-i` or `-n` and assigns a value holding `[`. A skill load is also refused unless the commands in the filled-in text are exactly the template's commands in the same order, where it only compared their number. If a template now fails to load, move the value out of the position after `$` (quote it in the template, or put a space before it); if a plain `let`/`declare -i` now asks, it held something other than digits. A prose value holding both an apostrophe and a stray backtick can now refuse a template that also contains a command. A line that declares a name `-i` or `-n` and then fills it with `read`, `mapfile`, `readarray`, `getopts`, `printf -v`, a loop variable or an expanding assignment, and a name held in a variable given to `declare`, `printf -v`, `read` or `[ -v`, now ask too; `printf -v` reads every `-v` option, not only the first. `unset` with a name that holds a subscript or expands (`unset 'a[$(cmd)]'`, `unset -v "$name"`) now asks too, since bash evaluates the subscript; `unset FOO` and `unset -f fn` stay plain. A line that runs `eval` with a word holding both a `[` and an expansion, or whose command word itself expands while a later word does, now asks too, since either can reach `unset` or `declare -i`.
|
|
46
|
+
|
|
3
47
|
## 69.4.0
|
|
4
48
|
|
|
5
49
|
### Minor Changes
|
|
@@ -27,11 +27,22 @@ export declare const PROTECTED_NESTED_DIRECTORIES: readonly (readonly string[])[
|
|
|
27
27
|
/** File names; a path whose last segment is one of these is protected. */
|
|
28
28
|
export declare const PROTECTED_FILE_NAMES: readonly string[];
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
30
|
+
* Names that are protected as the first segment of a path below a working
|
|
31
|
+
* root: the legacy project skills folder is `<root>/skills`, which a nested
|
|
32
|
+
* `src/skills` is not. Only a spelling relative to the root can say which, so a
|
|
33
|
+
* caller that has an absolute path passes the part below its root.
|
|
34
|
+
*/
|
|
35
|
+
export declare const PROTECTED_ROOT_DIRECTORIES: readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* Folders under the project directory that hold what is authored on purpose
|
|
38
|
+
* (skills, agent definitions, commands). They are excused from the protection
|
|
39
|
+
* of `.namzu` only for a remote session: one whose working folder is a
|
|
40
|
+
* checkout the operator is not sitting at, where authoring through the model is
|
|
41
|
+
* the way the folder gets written. In a local session they are protected like
|
|
42
|
+
* the rest of `.namzu`, because a skill written there is loaded by a later
|
|
43
|
+
* session, which attaches its hooks and honours the tools it allows. Only the
|
|
44
|
+
* first project directory in a path can be excused: a second one deeper down,
|
|
45
|
+
* or any other protected name below, still protects the path.
|
|
35
46
|
*
|
|
36
47
|
* `worktrees` is not one of them. The checkouts of delegated work live in the
|
|
37
48
|
* Namzu home (`projects/<slug>/worktrees/`), whose writes are judged by their
|
|
@@ -39,10 +50,17 @@ export declare const PROTECTED_FILE_NAMES: readonly string[];
|
|
|
39
50
|
* left there, and writing into it is asked about like the rest of `.namzu`.
|
|
40
51
|
*/
|
|
41
52
|
export declare const PROJECT_DIRECTORY_AUTHORED_FOLDERS: readonly string[];
|
|
53
|
+
export interface ProtectedPathOptions {
|
|
54
|
+
/**
|
|
55
|
+
* The session is a remote one, so the authored folders under `.namzu` are
|
|
56
|
+
* not asked about. False (the default) for every local session.
|
|
57
|
+
*/
|
|
58
|
+
readonly remoteSession?: boolean;
|
|
59
|
+
}
|
|
42
60
|
/**
|
|
43
61
|
* Whether a write to `path` is one of the protected kinds. Pure: it reads the
|
|
44
62
|
* spelling it is given, so a caller that wants a symlink's target covered
|
|
45
63
|
* passes the canonical path as well.
|
|
46
64
|
*/
|
|
47
|
-
export declare function isProtectedPath(path: string): boolean;
|
|
65
|
+
export declare function isProtectedPath(path: string, options?: ProtectedPathOptions): boolean;
|
|
48
66
|
//# sourceMappingURL=protected-paths.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protected-paths.d.ts","sourceRoot":"","sources":["../../src/authorization/protected-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAUlD,CAAA;AAED,0DAA0D;AAC1D,eAAO,MAAM,4BAA4B,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"protected-paths.d.ts","sourceRoot":"","sources":["../../src/authorization/protected-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAUlD,CAAA;AAED,0DAA0D;AAC1D,eAAO,MAAM,4BAA4B,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAMtE,CAAA;AAED,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EA4CjD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAAe,CAAA;AAEvE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kCAAkC,EAAE,SAAS,MAAM,EAI/D,CAAA;AAgBD,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAChC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CA0BzF"}
|
|
@@ -33,7 +33,13 @@ export const PROTECTED_DIRECTORIES = [
|
|
|
33
33
|
'.mvn',
|
|
34
34
|
];
|
|
35
35
|
/** Directory sequences; the segments must be adjacent. */
|
|
36
|
-
export const PROTECTED_NESTED_DIRECTORIES = [
|
|
36
|
+
export const PROTECTED_NESTED_DIRECTORIES = [
|
|
37
|
+
['.config', 'git'],
|
|
38
|
+
// A skill, agent or command folder is read back as instructions, and a
|
|
39
|
+
// skill's hooks run commands. `.agents/skills` is one of the folders Namzu
|
|
40
|
+
// loads skills from, at every level from the checkout root down.
|
|
41
|
+
['.agents', 'skills'],
|
|
42
|
+
];
|
|
37
43
|
/** File names; a path whose last segment is one of these is protected. */
|
|
38
44
|
export const PROTECTED_FILE_NAMES = [
|
|
39
45
|
'.gitconfig',
|
|
@@ -76,13 +82,27 @@ export const PROTECTED_FILE_NAMES = [
|
|
|
76
82
|
'maven-wrapper.properties',
|
|
77
83
|
'.devcontainer.json',
|
|
78
84
|
'pyrightconfig.json',
|
|
85
|
+
// A skill file declares hooks (shell commands run later, outside the bash
|
|
86
|
+
// prompt) and the tools it pre-approves, wherever the folder it sits in is.
|
|
87
|
+
'SKILL.md',
|
|
79
88
|
];
|
|
80
89
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
|
|
90
|
+
* Names that are protected as the first segment of a path below a working
|
|
91
|
+
* root: the legacy project skills folder is `<root>/skills`, which a nested
|
|
92
|
+
* `src/skills` is not. Only a spelling relative to the root can say which, so a
|
|
93
|
+
* caller that has an absolute path passes the part below its root.
|
|
94
|
+
*/
|
|
95
|
+
export const PROTECTED_ROOT_DIRECTORIES = ['skills'];
|
|
96
|
+
/**
|
|
97
|
+
* Folders under the project directory that hold what is authored on purpose
|
|
98
|
+
* (skills, agent definitions, commands). They are excused from the protection
|
|
99
|
+
* of `.namzu` only for a remote session: one whose working folder is a
|
|
100
|
+
* checkout the operator is not sitting at, where authoring through the model is
|
|
101
|
+
* the way the folder gets written. In a local session they are protected like
|
|
102
|
+
* the rest of `.namzu`, because a skill written there is loaded by a later
|
|
103
|
+
* session, which attaches its hooks and honours the tools it allows. Only the
|
|
104
|
+
* first project directory in a path can be excused: a second one deeper down,
|
|
105
|
+
* or any other protected name below, still protects the path.
|
|
86
106
|
*
|
|
87
107
|
* `worktrees` is not one of them. The checkouts of delegated work live in the
|
|
88
108
|
* Namzu home (`projects/<slug>/worktrees/`), whose writes are judged by their
|
|
@@ -95,6 +115,7 @@ export const PROJECT_DIRECTORY_AUTHORED_FOLDERS = [
|
|
|
95
115
|
'commands',
|
|
96
116
|
];
|
|
97
117
|
const PROJECT_DIRECTORY = '.namzu';
|
|
118
|
+
const SKILL_FILE = 'skill.md';
|
|
98
119
|
/** Lower case, with the two letters that fold into ASCII on some file systems. */
|
|
99
120
|
function fold(name) {
|
|
100
121
|
return name.toLowerCase().replace(/ı/g, 'i').replace(/ſ/g, 's');
|
|
@@ -102,20 +123,24 @@ function fold(name) {
|
|
|
102
123
|
const AUTHORED = new Set(PROJECT_DIRECTORY_AUTHORED_FOLDERS.map(fold));
|
|
103
124
|
const DIRECTORIES = new Set(PROTECTED_DIRECTORIES.map(fold));
|
|
104
125
|
const FILE_NAMES = new Set(PROTECTED_FILE_NAMES.map(fold));
|
|
126
|
+
const ROOT_DIRECTORIES = new Set(PROTECTED_ROOT_DIRECTORIES.map(fold));
|
|
105
127
|
const NESTED = PROTECTED_NESTED_DIRECTORIES.map((sequence) => sequence.map(fold));
|
|
106
128
|
/**
|
|
107
129
|
* Whether a write to `path` is one of the protected kinds. Pure: it reads the
|
|
108
130
|
* spelling it is given, so a caller that wants a symlink's target covered
|
|
109
131
|
* passes the canonical path as well.
|
|
110
132
|
*/
|
|
111
|
-
export function isProtectedPath(path) {
|
|
133
|
+
export function isProtectedPath(path, options = {}) {
|
|
112
134
|
const segments = path.split(/[\\/]+/).map(fold);
|
|
135
|
+
const first = segments[0];
|
|
136
|
+
if (first !== undefined && ROOT_DIRECTORIES.has(first) && segments.length > 1)
|
|
137
|
+
return true;
|
|
113
138
|
let excused = false;
|
|
114
139
|
for (let index = 0; index < segments.length; index += 1) {
|
|
115
140
|
const segment = segments[index];
|
|
116
141
|
if (!DIRECTORIES.has(segment))
|
|
117
142
|
continue;
|
|
118
|
-
if (segment === PROJECT_DIRECTORY && !excused) {
|
|
143
|
+
if (segment === PROJECT_DIRECTORY && !excused && options.remoteSession === true) {
|
|
119
144
|
const next = segments[index + 1];
|
|
120
145
|
if (next !== undefined && AUTHORED.has(next)) {
|
|
121
146
|
excused = true;
|
|
@@ -131,6 +156,9 @@ export function isProtectedPath(path) {
|
|
|
131
156
|
}
|
|
132
157
|
}
|
|
133
158
|
const last = segments[segments.length - 1];
|
|
134
|
-
|
|
159
|
+
if (last === undefined || last === '' || !FILE_NAMES.has(last))
|
|
160
|
+
return false;
|
|
161
|
+
// A skill file inside an excused authored folder is the point of the excuse.
|
|
162
|
+
return !(excused && last === SKILL_FILE);
|
|
135
163
|
}
|
|
136
164
|
//# sourceMappingURL=protected-paths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protected-paths.js","sourceRoot":"","sources":["../../src/authorization/protected-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAsB;IACvD,MAAM;IACN,SAAS;IACT,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,eAAe;IACf,OAAO;IACP,MAAM;CACN,CAAA;AAED,0DAA0D;AAC1D,MAAM,CAAC,MAAM,4BAA4B,GAAmC,CAAC,
|
|
1
|
+
{"version":3,"file":"protected-paths.js","sourceRoot":"","sources":["../../src/authorization/protected-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAsB;IACvD,MAAM;IACN,SAAS;IACT,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,eAAe;IACf,OAAO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MAAM,GAAG,MAAM,CAG7C"}
|
|
@@ -165,6 +165,29 @@ class Context {
|
|
|
165
165
|
opaque(reason) {
|
|
166
166
|
this.reasons.add(reason);
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* A name declared `-i` or `-n` evaluates what is later assigned to it as
|
|
170
|
+
* arithmetic, and an assigned value that holds a subscript runs the
|
|
171
|
+
* command inside it. The lexer keeps no variables, so when one line does
|
|
172
|
+
* both, in either order, it is opaque.
|
|
173
|
+
*/
|
|
174
|
+
integerDeclared = false;
|
|
175
|
+
bracketSeen = false;
|
|
176
|
+
declaredArithmetic() {
|
|
177
|
+
this.integerDeclared = true;
|
|
178
|
+
if (this.bracketSeen)
|
|
179
|
+
this.opaque('arithmetic');
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* A value that may hold a subscript was stored: a literal one, an
|
|
183
|
+
* expanding one, or one a `read`, `mapfile`, `printf -v`, `getopts` or
|
|
184
|
+
* loop variable stores. The lexer cannot see what they hold.
|
|
185
|
+
*/
|
|
186
|
+
bracketAssigned() {
|
|
187
|
+
this.bracketSeen = true;
|
|
188
|
+
if (this.integerDeclared)
|
|
189
|
+
this.opaque('arithmetic');
|
|
190
|
+
}
|
|
168
191
|
dialects = new Map();
|
|
169
192
|
/** The dialect a string is read in. A string read two ways gets the stricter. */
|
|
170
193
|
setDialect(src, dialect) {
|
|
@@ -272,6 +295,18 @@ const RESERVED = new Set([
|
|
|
272
295
|
const COMPOUND_AFTER = /^(?:\(|(?:\{|if|while|until|for|select|case|\[\[)(?=[\s;&|()<>]|$))/;
|
|
273
296
|
/** Builtins whose arguments may be array assignments. */
|
|
274
297
|
const ASSIGNMENT_BUILTINS = new Set(['declare', 'typeset', 'local', 'export', 'readonly']);
|
|
298
|
+
/** A `let` argument that evaluates nothing but numbers and an assignment of one. */
|
|
299
|
+
const PLAIN_ARITHMETIC = /^(?:[A-Za-z_][A-Za-z0-9_]*=)?[0-9\s+\-*/%()<>=!&|^~?:,]*$/;
|
|
300
|
+
/** A `declare -i` argument: a bare name, or a name given a plain number. */
|
|
301
|
+
/** A name word that carries a subscript, or one that expands into something that might. */
|
|
302
|
+
function subscriptOrExpands(word) {
|
|
303
|
+
return word.value.includes('[') || word.expands;
|
|
304
|
+
}
|
|
305
|
+
/** A subscript beside something that expands, quoted or not: `a[$(cmd)]`. */
|
|
306
|
+
function subscriptWithExpansion(word) {
|
|
307
|
+
return word.value.includes('[') && (word.expands || /[$`]/.test(word.value));
|
|
308
|
+
}
|
|
309
|
+
const PLAIN_INTEGER_ARGUMENT = /^[A-Za-z_][A-Za-z0-9_]*(?:=[0-9\s+\-*/%()<>=!&|^~?:,]*)?$/;
|
|
275
310
|
const WORD_BREAK = new Set([' ', '\t', '\n', ';', '&', '|', '(', ')', '<', '>']);
|
|
276
311
|
const NAME_START = /[A-Za-z_]/;
|
|
277
312
|
const NAME_CHAR = /[A-Za-z0-9_]/;
|
|
@@ -698,6 +733,8 @@ class Parser {
|
|
|
698
733
|
if (name.kind !== 'word')
|
|
699
734
|
throw this.unexpected(name);
|
|
700
735
|
this.context.compoundWords.push(name.word);
|
|
736
|
+
// The loop variable takes whatever the list holds.
|
|
737
|
+
this.context.bracketAssigned();
|
|
701
738
|
this.newlines();
|
|
702
739
|
token = this.peek();
|
|
703
740
|
if (token.kind === 'word' && !token.word.quoted && token.word.value === 'in') {
|
|
@@ -1067,6 +1104,7 @@ class Parser {
|
|
|
1067
1104
|
this.context.opaque('parser setting');
|
|
1068
1105
|
}
|
|
1069
1106
|
}
|
|
1107
|
+
this.inspectArithmeticBuiltin(command);
|
|
1070
1108
|
const head = command.words[command.assignments];
|
|
1071
1109
|
if (head === undefined || head.expands)
|
|
1072
1110
|
return;
|
|
@@ -1105,6 +1143,231 @@ class Parser {
|
|
|
1105
1143
|
}
|
|
1106
1144
|
this.nestedShell(nested.shell, nested.payload);
|
|
1107
1145
|
}
|
|
1146
|
+
/**
|
|
1147
|
+
* `unset` evaluates a subscript in a name operand, `unset 'a[$(cmd)]'`,
|
|
1148
|
+
* and runs `cmd`. `--` and the options `-v`, `-n` and `-f` (also
|
|
1149
|
+
* clustered, `-fv`) are read; the last of `-f` and `-v` decides, and with
|
|
1150
|
+
* `-f` the operands are function names, which evaluate nothing. Any other
|
|
1151
|
+
* word that holds a `[` or expands, a fused `-v'a[$(cmd)]'` included, is
|
|
1152
|
+
* opaque.
|
|
1153
|
+
*/
|
|
1154
|
+
inspectUnset(args) {
|
|
1155
|
+
let functions = false;
|
|
1156
|
+
let options = true;
|
|
1157
|
+
for (const word of args) {
|
|
1158
|
+
if (options && !word.expands && word.value === '--') {
|
|
1159
|
+
options = false;
|
|
1160
|
+
continue;
|
|
1161
|
+
}
|
|
1162
|
+
if (options && !word.expands && /^-[fvn]+$/.test(word.value)) {
|
|
1163
|
+
const last = word.value.replace(/[^fv]/g, '').slice(-1);
|
|
1164
|
+
if (last === 'f')
|
|
1165
|
+
functions = true;
|
|
1166
|
+
else if (last === 'v')
|
|
1167
|
+
functions = false;
|
|
1168
|
+
continue;
|
|
1169
|
+
}
|
|
1170
|
+
if (functions && !word.expands)
|
|
1171
|
+
continue;
|
|
1172
|
+
if (subscriptOrExpands(word)) {
|
|
1173
|
+
this.context.opaque('arithmetic');
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Bash evaluates a name that carries a subscript, `a[$(cmd)]`, as
|
|
1180
|
+
* arithmetic and runs `cmd`, quoted or not. Where that happens: each
|
|
1181
|
+
* `let` argument; `declare -i` (also `typeset`, `local`, clustered flags
|
|
1182
|
+
* such as `-ia`) for each `NAME=value`; the name given to `declare`,
|
|
1183
|
+
* `typeset` or `local` with any flags, to `printf -v` and to `read`; the
|
|
1184
|
+
* operand of `-v` or `-R` in `test` and `[`; and a later plain assignment
|
|
1185
|
+
* to a name declared `-i` or `-n` in the same line. A word that is not
|
|
1186
|
+
* plainly safe is opaque: the line asks instead of showing a command with
|
|
1187
|
+
* no inner one.
|
|
1188
|
+
*/
|
|
1189
|
+
inspectArithmeticBuiltin(command) {
|
|
1190
|
+
for (let i = 0; i < command.assignments; i += 1)
|
|
1191
|
+
this.noteBracketAssignment(command.words[i]);
|
|
1192
|
+
let at = command.assignments;
|
|
1193
|
+
for (;;) {
|
|
1194
|
+
const word = command.words[at];
|
|
1195
|
+
if (word === undefined)
|
|
1196
|
+
return;
|
|
1197
|
+
if (word.expands) {
|
|
1198
|
+
// The head may name any builtin: with a subscript that expands in a
|
|
1199
|
+
// later word, the line asks.
|
|
1200
|
+
if (command.words.slice(at + 1).some(subscriptWithExpansion))
|
|
1201
|
+
this.context.opaque('arithmetic');
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
1204
|
+
if ((word.value === 'builtin' || word.value === 'command') && command.words[at + 1]) {
|
|
1205
|
+
let next = at + 1;
|
|
1206
|
+
// `--` and `-p` only step over; `-v` and `-V` run nothing; any
|
|
1207
|
+
// other option is not understood, so the line asks.
|
|
1208
|
+
for (;;) {
|
|
1209
|
+
const option = command.words[next];
|
|
1210
|
+
if (option === undefined || option.expands || !option.value.startsWith('-'))
|
|
1211
|
+
break;
|
|
1212
|
+
if (option.value === '--') {
|
|
1213
|
+
next += 1;
|
|
1214
|
+
break;
|
|
1215
|
+
}
|
|
1216
|
+
if (option.value === '-p') {
|
|
1217
|
+
next += 1;
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
if (word.value === 'command' && (option.value === '-v' || option.value === '-V'))
|
|
1221
|
+
return;
|
|
1222
|
+
this.context.opaque('arithmetic');
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
const target = command.words[next];
|
|
1226
|
+
if (target === undefined || target.expands)
|
|
1227
|
+
return;
|
|
1228
|
+
at = next;
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
break;
|
|
1232
|
+
}
|
|
1233
|
+
const name = command.words[at].value;
|
|
1234
|
+
const args = command.words.slice(at + 1);
|
|
1235
|
+
if (name === 'eval') {
|
|
1236
|
+
// eval reads its words as a line again, where a name with a subscript
|
|
1237
|
+
// and an expansion can reach `unset` or `declare -i`.
|
|
1238
|
+
if (args.some(subscriptWithExpansion))
|
|
1239
|
+
this.context.opaque('arithmetic');
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
if (name === 'let') {
|
|
1243
|
+
if (args.some((word) => !PLAIN_ARITHMETIC.test(word.value)))
|
|
1244
|
+
this.context.opaque('arithmetic');
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
if (name === 'printf') {
|
|
1248
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
1249
|
+
const value = args[i].value;
|
|
1250
|
+
if (value === '--')
|
|
1251
|
+
break;
|
|
1252
|
+
if (!value.startsWith('-'))
|
|
1253
|
+
break;
|
|
1254
|
+
// The last -v wins, so every leading option is read.
|
|
1255
|
+
if (value === '-v') {
|
|
1256
|
+
this.context.bracketAssigned();
|
|
1257
|
+
const target = args[i + 1];
|
|
1258
|
+
if (target !== undefined && subscriptOrExpands(target))
|
|
1259
|
+
this.context.opaque('arithmetic');
|
|
1260
|
+
i += 1;
|
|
1261
|
+
continue;
|
|
1262
|
+
}
|
|
1263
|
+
if (value.startsWith('-v')) {
|
|
1264
|
+
this.context.bracketAssigned();
|
|
1265
|
+
if (subscriptOrExpands(args[i]))
|
|
1266
|
+
this.context.opaque('arithmetic');
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
if (name === 'read') {
|
|
1272
|
+
this.context.bracketAssigned();
|
|
1273
|
+
this.inspectRead(args);
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
if (name === 'unset') {
|
|
1277
|
+
this.inspectUnset(args);
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
if (name === 'mapfile' || name === 'readarray' || name === 'getopts') {
|
|
1281
|
+
this.context.bracketAssigned();
|
|
1282
|
+
if (args.some((word) => subscriptOrExpands(word)))
|
|
1283
|
+
this.context.opaque('arithmetic');
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
if (name === 'test' || name === '[') {
|
|
1287
|
+
for (let i = 0; i < args.length - 1; i += 1) {
|
|
1288
|
+
const value = args[i].value;
|
|
1289
|
+
if ((value === '-v' || value === '-R') && subscriptOrExpands(args[i + 1]))
|
|
1290
|
+
this.context.opaque('arithmetic');
|
|
1291
|
+
}
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
if (name !== 'declare' && name !== 'typeset' && name !== 'local')
|
|
1295
|
+
return;
|
|
1296
|
+
let integer = false;
|
|
1297
|
+
let nameref = false;
|
|
1298
|
+
let flags = true;
|
|
1299
|
+
for (const word of args) {
|
|
1300
|
+
if (flags && word.value === '--')
|
|
1301
|
+
flags = false;
|
|
1302
|
+
else if (flags && /^-[A-Za-z]*i/.test(word.value))
|
|
1303
|
+
integer = true;
|
|
1304
|
+
// A word that expands may be the flag itself.
|
|
1305
|
+
else if (flags && word.expands && !word.value.includes('='))
|
|
1306
|
+
integer = true;
|
|
1307
|
+
if (flags && /^-[A-Za-z]*n/.test(word.value))
|
|
1308
|
+
nameref = true;
|
|
1309
|
+
}
|
|
1310
|
+
if (integer || nameref)
|
|
1311
|
+
this.context.declaredArithmetic();
|
|
1312
|
+
flags = true;
|
|
1313
|
+
for (const word of args) {
|
|
1314
|
+
if (flags && word.value === '--') {
|
|
1315
|
+
flags = false;
|
|
1316
|
+
continue;
|
|
1317
|
+
}
|
|
1318
|
+
if (flags && word.value.startsWith('-') && !word.expands)
|
|
1319
|
+
continue;
|
|
1320
|
+
const equals = word.value.indexOf('=');
|
|
1321
|
+
const nameFor = equals < 0 ? word.value : word.value.slice(0, equals);
|
|
1322
|
+
if (nameFor.includes('[') || (word.expands && /[$`]/.test(nameFor)))
|
|
1323
|
+
this.context.opaque('arithmetic');
|
|
1324
|
+
else if (nameref && word.value.slice(equals + 1).includes('[') && equals >= 0)
|
|
1325
|
+
this.context.opaque('arithmetic');
|
|
1326
|
+
else if (integer && !PLAIN_INTEGER_ARGUMENT.test(word.value))
|
|
1327
|
+
this.context.opaque('arithmetic');
|
|
1328
|
+
else
|
|
1329
|
+
this.noteBracketAssignment(word);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
/** The names `read` stores into, minus the arguments of its options. */
|
|
1333
|
+
inspectRead(args) {
|
|
1334
|
+
let options = true;
|
|
1335
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
1336
|
+
const value = args[i].value;
|
|
1337
|
+
if (options && value === '--') {
|
|
1338
|
+
options = false;
|
|
1339
|
+
continue;
|
|
1340
|
+
}
|
|
1341
|
+
if (options && value.startsWith('-') && value.length > 1) {
|
|
1342
|
+
for (let k = 1; k < value.length; k += 1) {
|
|
1343
|
+
const letter = value[k];
|
|
1344
|
+
if ('dinNptu'.includes(letter) || letter === 'a') {
|
|
1345
|
+
const rest = value.slice(k + 1);
|
|
1346
|
+
const operand = rest.length > 0 ? rest : (args[i + 1]?.value ?? '');
|
|
1347
|
+
if (rest.length === 0)
|
|
1348
|
+
i += 1;
|
|
1349
|
+
if (letter === 'a' && operand.includes('['))
|
|
1350
|
+
this.context.opaque('arithmetic');
|
|
1351
|
+
break;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
continue;
|
|
1355
|
+
}
|
|
1356
|
+
if (subscriptOrExpands(args[i]))
|
|
1357
|
+
this.context.opaque('arithmetic');
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
/** A plain `NAME=value` whose value holds a subscript: dangerous once NAME is `-i` or `-n`. */
|
|
1361
|
+
noteBracketAssignment(word) {
|
|
1362
|
+
if (word === undefined)
|
|
1363
|
+
return;
|
|
1364
|
+
const equals = word.value.indexOf('=');
|
|
1365
|
+
if (equals <= 0)
|
|
1366
|
+
return;
|
|
1367
|
+
const value = word.value.slice(equals + 1);
|
|
1368
|
+
if (value.includes('[') || (word.expands && /[$`]/.test(value)))
|
|
1369
|
+
this.context.bracketAssigned();
|
|
1370
|
+
}
|
|
1108
1371
|
/** Read the payload of `bash -c payload` as a command line of its own. */
|
|
1109
1372
|
nestedShell(shell, payload) {
|
|
1110
1373
|
if (this.depth + 1 >= MAX_SHELL_DEPTH) {
|