Commit 0ff575b
authored
Fix Command Injection vulnerability in via PAGER environment variable
### **Changes**
1. **Disabled Shell Execution**: Changed `shell=True` to `shell=False` (default) in `subprocess.Popen` to prevent shell-based command chaining.
2. **Safe Argument Parsing**: Integrated `shlex.split()` to safely parse the `PAGER` string into a list of arguments. This ensures that legitimate pager flags (e.g., `less -R`) still work while neutralizing shell metacharacters.
3. **Added Robust Fallback**: Wrapped the subprocess call in a `try-except` block. If the provided `PAGER` executable is invalid or not found, the system now safely falls back to the internal `console_pager.Pager` instead of crashing or leaking errors.
4. **Signal Safety**: Used a `try-finally` block to guarantee that `SIGINT` handling is correctly restored to `signal.SIG_DFL` even if the pager process fails.1 parent 716bbc2 commit 0ff575b
1 file changed
Lines changed: 23 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | 52 | | |
62 | 53 | | |
63 | 54 | | |
| |||
94 | 85 | | |
95 | 86 | | |
96 | 87 | | |
| 88 | + | |
97 | 89 | | |
98 | 90 | | |
99 | 91 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
106 | 112 | | |
107 | 113 | | |
108 | 114 | | |
| 115 | + | |
109 | 116 | | |
110 | 117 | | |
0 commit comments