@mmmbuto/gemini-cli-termux 0.24.2-termux → 0.24.4-termux

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.
@@ -4,128 +4,6 @@ This guide covers security considerations, performance optimization, debugging
4
4
  techniques, and privacy considerations for developing and deploying hooks in
5
5
  Gemini CLI.
6
6
 
7
- ## Security considerations
8
-
9
- ### Validate all inputs
10
-
11
- Never trust data from hooks without validation. Hook inputs may contain
12
- user-provided data that could be malicious:
13
-
14
- ```bash
15
- #!/usr/bin/env bash
16
- input=$(cat)
17
-
18
- # Validate JSON structure
19
- if ! echo "$input" | jq empty 2>/dev/null; then
20
- echo "Invalid JSON input" >&2
21
- exit 1
22
- fi
23
-
24
- # Validate required fields
25
- tool_name=$(echo "$input" | jq -r '.tool_name // empty')
26
- if [ -z "$tool_name" ]; then
27
- echo "Missing tool_name field" >&2
28
- exit 1
29
- fi
30
- ```
31
-
32
- ### Use timeouts
33
-
34
- Set reasonable timeouts to prevent hooks from hanging indefinitely:
35
-
36
- ```json
37
- {
38
- "hooks": {
39
- "BeforeTool": [
40
- {
41
- "matcher": "*",
42
- "hooks": [
43
- {
44
- "name": "slow-validator",
45
- "type": "command",
46
- "command": "./hooks/validate.sh",
47
- "timeout": 5000
48
- }
49
- ]
50
- }
51
- ]
52
- }
53
- }
54
- ```
55
-
56
- **Recommended timeouts:**
57
-
58
- - Fast validation: 1000-5000ms
59
- - Network requests: 10000-30000ms
60
- - Heavy computation: 30000-60000ms
61
-
62
- ### Limit permissions
63
-
64
- Run hooks with minimal required permissions:
65
-
66
- ```bash
67
- #!/usr/bin/env bash
68
- # Don't run as root
69
- if [ "$EUID" -eq 0 ]; then
70
- echo "Hook should not run as root" >&2
71
- exit 1
72
- fi
73
-
74
- # Check file permissions before writing
75
- if [ -w "$file_path" ]; then
76
- # Safe to write
77
- else
78
- echo "Insufficient permissions" >&2
79
- exit 1
80
- fi
81
- ```
82
-
83
- ### Scan for secrets
84
-
85
- Use `BeforeTool` hooks to prevent committing sensitive data:
86
-
87
- ```javascript
88
- const SECRET_PATTERNS = [
89
- /api[_-]?key\s*[:=]\s*['"]?[a-zA-Z0-9_-]{20,}['"]?/i,
90
- /password\s*[:=]\s*['"]?[^\s'"]{8,}['"]?/i,
91
- /secret\s*[:=]\s*['"]?[a-zA-Z0-9_-]{20,}['"]?/i,
92
- /AKIA[0-9A-Z]{16}/, // AWS access key
93
- /ghp_[a-zA-Z0-9]{36}/, // GitHub personal access token
94
- /sk-[a-zA-Z0-9]{48}/, // OpenAI API key
95
- ];
96
-
97
- function containsSecret(content) {
98
- return SECRET_PATTERNS.some((pattern) => pattern.test(content));
99
- }
100
- ```
101
-
102
- ### Review external scripts
103
-
104
- Always review hook scripts from untrusted sources before enabling them:
105
-
106
- ```bash
107
- # Review before installing
108
- cat third-party-hook.sh | less
109
-
110
- # Check for suspicious patterns
111
- grep -E 'curl|wget|ssh|eval' third-party-hook.sh
112
-
113
- # Verify hook source
114
- ls -la third-party-hook.sh
115
- ```
116
-
117
- ### Sandbox untrusted hooks
118
-
119
- For maximum security, consider running untrusted hooks in isolated environments:
120
-
121
- ```bash
122
- # Run hook in Docker container
123
- docker run --rm \
124
- -v "$GEMINI_PROJECT_DIR:/workspace:ro" \
125
- -i untrusted-hook-image \
126
- /hook-script.sh < input.json
127
- ```
128
-
129
7
  ## Performance
130
8
 
131
9
  ### Keep hooks fast
@@ -140,11 +18,13 @@ const data2 = await fetch(url2).then((r) => r.json());
140
18
  const data3 = await fetch(url3).then((r) => r.json());
141
19
 
142
20
  // Prefer parallel operations for better performance
143
- const [data1, data2, data3] = await Promise.all([
144
- fetch(url1).then((r) => r.json()),
145
- fetch(url2).then((r) => r.json()),
146
- fetch(url3).then((r) => r.json()),
147
- ]);
21
+ // Start requests concurrently
22
+ const p1 = fetch(url1).then((r) => r.json());
23
+ const p2 = fetch(url2).then((r) => r.json());
24
+ const p3 = fetch(url3).then((r) => r.json());
25
+
26
+ // Wait for all results
27
+ const [data1, data2, data3] = await Promise.all([p1, p2, p3]);
148
28
  ```
149
29
 
150
30
  ### Cache expensive operations
@@ -714,6 +594,176 @@ if [ -f "$GEMINI_PROJECT_DIR/.env" ]; then
714
594
  fi
715
595
  ```
716
596
 
597
+ ## Using Hooks Securely
598
+
599
+ ### Threat Model
600
+
601
+ Understanding where hooks come from and what they can do is critical for secure
602
+ usage.
603
+
604
+ | Hook Source | Description |
605
+ | :---------------------------- | :------------------------------------------------------------------------------------------------------------------------- |
606
+ | **System** | Configured by system administrators (e.g., `/etc/gemini-cli/settings.json`, `/Library/...`). Assumed to be the **safest**. |
607
+ | **User** (`~/.gemini/...`) | Configured by you. You are responsible for ensuring they are safe. |
608
+ | **Extensions** | You explicitly approve and install these. Security depends on the extension source (integrity). |
609
+ | **Project** (`./.gemini/...`) | **Untrusted by default.** Safest in trusted internal repos; higher risk in third-party/public repos. |
610
+
611
+ #### Project Hook Security
612
+
613
+ When you open a project with hooks defined in `.gemini/settings.json`:
614
+
615
+ 1. **Detection**: Gemini CLI detects the hooks.
616
+ 2. **Identification**: A unique identity is generated for each hook based on its
617
+ `name` and `command`.
618
+ 3. **Warning**: If this specific hook identity has not been seen before, a
619
+ **warning** is displayed.
620
+ 4. **Execution**: The hook is executed (unless specific security settings block
621
+ it).
622
+ 5. **Trust**: The hook is marked as "trusted" for this project.
623
+
624
+ > [!IMPORTANT] **Modification Detection**: If the `command` string of a project
625
+ > hook is changed (e.g., by a `git pull`), its identity changes. Gemini CLI will
626
+ > treat it as a **new, untrusted hook** and warn you again. This prevents
627
+ > malicious actors from silently swapping a verified command for a malicious
628
+ > one.
629
+
630
+ ### Risks
631
+
632
+ | Risk | Description |
633
+ | :--------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- |
634
+ | **Arbitrary Code Execution** | Hooks run as your user. They can do anything you can do (delete files, install software). |
635
+ | **Data Exfiltration** | A hook could read your input (prompts), output (code), or environment variables (`GEMINI_API_KEY`) and send them to a remote server. |
636
+ | **Prompt Injection** | Malicious content in a file or web page could trick an LLM into running a tool that triggers a hook in an unexpected way. |
637
+
638
+ ### Mitigation Strategies
639
+
640
+ #### Verify the source
641
+
642
+ **Verify the source** of any project hooks or extensions before enabling them.
643
+
644
+ - For open-source projects, a quick review of the hook scripts is recommended.
645
+ - For extensions, ensure you trust the author or publisher (e.g., verified
646
+ publishers, well-known community members).
647
+ - Be cautious with obfuscated scripts or compiled binaries from unknown sources.
648
+
649
+ #### Sanitize Environment
650
+
651
+ Hooks inherit the environment of the Gemini CLI process, which may include
652
+ sensitive API keys. Gemini CLI attempts to sanitize sensitive variables, but you
653
+ should be cautious.
654
+
655
+ - **Avoid printing environment variables** to stdout/stderr unless necessary.
656
+ - **Use `.env` files** to securely manage sensitive variables, ensuring they are
657
+ excluded from version control.
658
+
659
+ **System Administrators:** You can enforce environment variable redaction by
660
+ default in the system configuration (e.g., `/etc/gemini-cli/settings.json`):
661
+
662
+ ```json
663
+ {
664
+ "security": {
665
+ "environmentVariableRedaction": {
666
+ "enabled": true,
667
+ "blocked": ["MY_SECRET_KEY"],
668
+ "allowed": ["SAFE_VAR"]
669
+ }
670
+ }
671
+ }
672
+ ```
673
+
674
+ ## Authoring Secure Hooks
675
+
676
+ When writing your own hooks, follow these practices to ensure they are robust
677
+ and secure.
678
+
679
+ ### Validate all inputs
680
+
681
+ Never trust data from hooks without validation. Hook inputs often come from the
682
+ LLM or user prompts, which can be manipulated.
683
+
684
+ ```bash
685
+ #!/usr/bin/env bash
686
+ input=$(cat)
687
+
688
+ # Validate JSON structure
689
+ if ! echo "$input" | jq empty 2>/dev/null; then
690
+ echo "Invalid JSON input" >&2
691
+ exit 1
692
+ fi
693
+
694
+ # Validate tool_name explicitly
695
+ tool_name=$(echo "$input" | jq -r '.tool_name // empty')
696
+ if [[ "$tool_name" != "write_file" && "$tool_name" != "read_file" ]]; then
697
+ echo "Unexpected tool: $tool_name" >&2
698
+ exit 1
699
+ fi
700
+ ```
701
+
702
+ ### Use timeouts
703
+
704
+ Prevent denial-of-service (hanging agents) by enforcing timeouts. Gemini CLI
705
+ defaults to 60 seconds, but you should set stricter limits for fast hooks.
706
+
707
+ ```json
708
+ {
709
+ "hooks": {
710
+ "BeforeTool": [
711
+ {
712
+ "matcher": "*",
713
+ "hooks": [
714
+ {
715
+ "name": "fast-validator",
716
+ "command": "./hooks/validate.sh",
717
+ "timeout": 5000 // 5 seconds
718
+ }
719
+ ]
720
+ }
721
+ ]
722
+ }
723
+ }
724
+ ```
725
+
726
+ ### Limit permissions
727
+
728
+ Run hooks with minimal required permissions:
729
+
730
+ ```bash
731
+ #!/usr/bin/env bash
732
+ # Don't run as root
733
+ if [ "$EUID" -eq 0 ]; then
734
+ echo "Hook should not run as root" >&2
735
+ exit 1
736
+ fi
737
+
738
+ # Check file permissions before writing
739
+ if [ -w "$file_path" ]; then
740
+ # Safe to write
741
+ else
742
+ echo "Insufficient permissions" >&2
743
+ exit 1
744
+ fi
745
+ ```
746
+
747
+ ### Example: Secret Scanner
748
+
749
+ Use `BeforeTool` hooks to prevent committing sensitive data. This is a powerful
750
+ pattern for enhancing security in your workflow.
751
+
752
+ ```javascript
753
+ const SECRET_PATTERNS = [
754
+ /api[_-]?key\s*[:=]\s*['"]?[a-zA-Z0-9_-]{20,}['"]?/i,
755
+ /password\s*[:=]\s*['"]?[^\s'"]{8,}['"]?/i,
756
+ /secret\s*[:=]\s*['"]?[a-zA-Z0-9_-]{20,}['"]?/i,
757
+ /AKIA[0-9A-Z]{16}/, // AWS access key
758
+ /ghp_[a-zA-Z0-9]{36}/, // GitHub personal access token
759
+ /sk-[a-zA-Z0-9]{48}/, // OpenAI API key
760
+ ];
761
+
762
+ function containsSecret(content) {
763
+ return SECRET_PATTERNS.some((pattern) => pattern.test(content));
764
+ }
765
+ ```
766
+
717
767
  ## Privacy considerations
718
768
 
719
769
  Hook inputs and outputs may contain sensitive information. Gemini CLI respects
@@ -27,6 +27,28 @@ With hooks, you can:
27
27
  Hooks run synchronously as part of the agent loop—when a hook event fires,
28
28
  Gemini CLI waits for all matching hooks to complete before continuing.
29
29
 
30
+ ## Security and Risks
31
+
32
+ > [!WARNING] **Hooks execute arbitrary code with your user privileges.**
33
+
34
+ By configuring hooks, you are explicitly allowing Gemini CLI to run shell
35
+ commands on your machine. Malicious or poorly configured hooks can:
36
+
37
+ - **Exfiltrate data**: Read sensitive files (`.env`, ssh keys) and send them to
38
+ remote servers.
39
+ - **Modify system**: Delete files, install malware, or change system settings.
40
+ - **Consume resources**: Run infinite loops or crash your system.
41
+
42
+ **Project-level hooks** (in `.gemini/settings.json`) and **Extension hooks** are
43
+ particularly risky when opening third-party projects or extensions from
44
+ untrusted authors. Gemini CLI will **warn you** the first time it detects a new
45
+ project hook (identified by its name and command), but it is **your
46
+ responsibility** to review these hooks (and any installed extensions) before
47
+ trusting them.
48
+
49
+ See [Security Considerations](best-practices.md#using-hooks-securely) for a
50
+ detailed threat model and mitigation strategies.
51
+
30
52
  ## Core concepts
31
53
 
32
54
  ### Hook events
@@ -88,6 +88,10 @@
88
88
  "label": "Session Management",
89
89
  "slug": "docs/cli/session-management"
90
90
  },
91
+ {
92
+ "label": "Agent Skills",
93
+ "slug": "docs/cli/skills"
94
+ },
91
95
  {
92
96
  "label": "Settings",
93
97
  "slug": "docs/cli/settings"