@hasna/hooks 0.15.0 → 0.15.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"package": "@hasna/hooks",
|
|
4
|
-
"version": "0.15.
|
|
4
|
+
"version": "0.15.1",
|
|
5
5
|
"hooks": {
|
|
6
6
|
"affected-tests": {
|
|
7
7
|
"version": "0.1.0",
|
|
@@ -276,7 +276,7 @@
|
|
|
276
276
|
"trash-guard": {
|
|
277
277
|
"version": "0.1.2",
|
|
278
278
|
"script": "hooks/hook-trash-guard/src/hook.ts",
|
|
279
|
-
"sha256": "
|
|
279
|
+
"sha256": "88ed81d67d8618a62eecdb58e748cb8187e3005e92349c9eee3c9b756bbcc0ac"
|
|
280
280
|
},
|
|
281
281
|
"typecheck-gate": {
|
|
282
282
|
"version": "0.1.0",
|
|
@@ -1559,35 +1559,35 @@ const OWN_SCRATCH_MIN_PREFIX = 8;
|
|
|
1559
1559
|
/** A `..` path component anywhere in the command (after a separator, quote or start). */
|
|
1560
1560
|
const PARENT_COMPONENT = /(?:^|[\s/'"`=:;&|()<>{},])\.\.(?=$|[\s/'"`;&|()<>{},])/;
|
|
1561
1561
|
/** The only command words a command using the own-scratch exception may run, written literally. */
|
|
1562
|
-
const DELETE_ONLY_WORD = /^(?:\/bin\/|\/usr\/bin\/)?(?:rm|rmdir
|
|
1562
|
+
const DELETE_ONLY_WORD = /^(?:\/bin\/|\/usr\/bin\/)?(?:rm|rmdir)$/;
|
|
1563
1563
|
/** Shell constructs that can run or build a command the word check cannot see. */
|
|
1564
1564
|
const HIDDEN_COMMAND = /\$\(|`|<\(|>\(|\$\{|\$'|\\\n/;
|
|
1565
|
-
/**
|
|
1566
|
-
const
|
|
1565
|
+
/** A leading `cd` to one plain absolute (or `~/`) path: no option, no quote, no variable. */
|
|
1566
|
+
const LEADING_CD = /^cd\s+(?:\/|~\/)[A-Za-z0-9._@+\/-]*$/;
|
|
1567
1567
|
|
|
1568
1568
|
/**
|
|
1569
1569
|
* Whether the command as a whole may use the own-scratch exception at all. It must be
|
|
1570
1570
|
* made only of deletes: every simple command (split on `;`, `&`, `|` and newlines, more
|
|
1571
1571
|
* finely than the shell would, so a quoted separator only splits more) starts with the
|
|
1572
|
-
* literal word `rm
|
|
1573
|
-
*
|
|
1574
|
-
*
|
|
1575
|
-
*
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
1578
|
-
*
|
|
1579
|
-
*
|
|
1572
|
+
* literal word `rm` or `rmdir` (optionally `/bin/` or `/usr/bin/`), except that the
|
|
1573
|
+
* FIRST may be `cd <one plain absolute path>`. That `cd` is what lets a session whose
|
|
1574
|
+
* working folder is a repository checkout leave it, as the repo-checkout guard's own
|
|
1575
|
+
* logic requires; it cannot change what is deleted, because every target must be
|
|
1576
|
+
* written as an absolute path (the call site's check). `find` is not admitted: its
|
|
1577
|
+
* actions can be assembled from pieces no word check reads (`{-exec,}`, `-exe$*c`).
|
|
1578
|
+
* Nothing may build a command the words cannot show (`$(…)`, backticks, any
|
|
1579
|
+
* parenthesis — process substitution, zsh `=(…)` and glob qualifiers included —,
|
|
1580
|
+
* `${…}`, `$'…'`, a line continuation): anything else could make or move a link in the
|
|
1581
|
+
* same run, which a check made before the command cannot see. Also refused: any `..`
|
|
1582
|
+
* component (a symbolic link followed by `..` is resolved by the kernel from the link's
|
|
1583
|
+
* target, which a textual path check cannot see).
|
|
1580
1584
|
*/
|
|
1581
1585
|
export function ownScratchCommandAllowed(command: string): boolean {
|
|
1582
1586
|
if (PARENT_COMPONENT.test(command) || HIDDEN_COMMAND.test(command) || /[()]/.test(command)) return false;
|
|
1583
1587
|
const pieces = command.split(/[;&|\n\r]+/).map((piece) => piece.trim()).filter(Boolean);
|
|
1588
|
+
if (pieces.length > 0 && LEADING_CD.test(pieces[0])) pieces.shift();
|
|
1584
1589
|
if (pieces.length === 0) return false;
|
|
1585
|
-
return pieces.every((piece) =>
|
|
1586
|
-
const first = piece.split(/\s+/)[0];
|
|
1587
|
-
if (!DELETE_ONLY_WORD.test(first)) return false;
|
|
1588
|
-
if (!first.endsWith("find")) return true;
|
|
1589
|
-
return !/['"\\]/.test(piece) && !FIND_RUNS_SOMETHING.test(piece);
|
|
1590
|
-
});
|
|
1590
|
+
return pieces.every((piece) => DELETE_ONLY_WORD.test(piece.split(/\s+/)[0]));
|
|
1591
1591
|
}
|
|
1592
1592
|
|
|
1593
1593
|
/**
|
|
@@ -1656,7 +1656,7 @@ function ownScratchHint(targetPath: string, rule: ProtectedPathRule): string {
|
|
|
1656
1656
|
if (rule.label !== "Hasna state root ~/.hasna") return "";
|
|
1657
1657
|
const scratchRoot = join(rule.root, "scratchpad", "scratch");
|
|
1658
1658
|
if (!isInsidePath(resolve(targetPath), scratchRoot) || resolve(targetPath) === scratchRoot) return "";
|
|
1659
|
-
return " To remove content of your own scratch folder, write each target as an absolute path below ~/.hasna/scratchpad/scratch/<your session id>/, with no `..`, in a command made only of rm
|
|
1659
|
+
return " To remove content of your own scratch folder, write each target as an absolute path below ~/.hasna/scratchpad/scratch/<your session id>/, with no `..`, in a command made only of rm or rmdir, optionally after one leading `cd <absolute path>` (for example out of a repository checkout).";
|
|
1660
1660
|
}
|
|
1661
1661
|
|
|
1662
1662
|
/** True only for an existing directory that is not itself a symbolic link. */
|
|
@@ -90,12 +90,12 @@ counts, and the rewrite replaces only the verb, behind its wrappers.
|
|
|
90
90
|
written word does not show, is refused.
|
|
91
91
|
- A command this hook cannot follow to its end, when it names a delete verb,
|
|
92
92
|
`find -delete` or `git clean` (read with `$'…'` and `$"…"` decoded and in any
|
|
93
|
-
case, HO-00226), or its scan finds a delete (HO-00208). The causes
|
|
94
|
-
substitution, an extended glob such as `@(a|b)`, a
|
|
95
|
-
substitution,
|
|
96
|
-
missed. A here-document is read as bash reads it: the rest
|
|
97
|
-
(`cat <<EOF && rm x`), `<<-`
|
|
98
|
-
to the end of the command.
|
|
93
|
+
case, HO-00226), or its scan finds a delete (HO-00208). The causes include
|
|
94
|
+
an unterminated quote or substitution, an extended glob such as `@(a|b)`, a
|
|
95
|
+
`case` word inside a substitution, and a `$'…'` spelling that shows a delete
|
|
96
|
+
the plain reading missed. A here-document is read as bash reads it: the rest
|
|
97
|
+
of its operator's line is still the command (`cat <<EOF && rm x`), `<<-`
|
|
98
|
+
strips tabs, and a body with no terminator runs to the end of the command.
|
|
99
99
|
- The protected class, below.
|
|
100
100
|
|
|
101
101
|
A `#` comment is read as bash reads it too (HO-00210). A `#` that starts a
|
|
@@ -2547,8 +2547,9 @@ function scanVerdict(scanned: ScanResult, command: string): CodewithHookOutput |
|
|
|
2547
2547
|
// can be trusted: the lexer stopped, a `case` word sits inside a
|
|
2548
2548
|
// substitution (scanReading), or the `$'…'` spelling found what the plain
|
|
2549
2549
|
// reading missed (scanCommand). A delete the scan found, or a delete-verb
|
|
2550
|
-
// word, means it might be a delete: refuse. The text match alone misses a
|
|
2551
|
-
// scan still read (`r""m` after two here-documents;
|
|
2550
|
+
// word, means it might be a delete: refuse. The text match alone misses a
|
|
2551
|
+
// quoted verb that the scan still read (`r""m` after two here-documents;
|
|
2552
|
+
// HO-00208 B1).
|
|
2552
2553
|
return scanned.rmHits.length > 0 || scanned.handoffHits.length > 0 || mentionsDeleteVerb(command)
|
|
2553
2554
|
|| mentionsRefusedDeleteForm(command)
|
|
2554
2555
|
? deny(
|
package/package.json
CHANGED