Skip to content

Commit e51969b

Browse files
Update project files and scripts for improved functionality and security
1 parent 72f31de commit e51969b

32 files changed

Lines changed: 5485 additions & 196 deletions

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ jobs:
1717
sudo apt-get update
1818
sudo apt-get install -y shellcheck ghostscript
1919
20-
- name: Run ShellCheck
20+
- name: Run ShellCheck on all shell scripts
2121
run: |
22-
shellcheck compresskit-pdf
23-
shellcheck install.sh
22+
find . -type f -name "*.sh" -exec shellcheck -x {} \; || true
23+
24+
- name: Run ShellCheck on main scripts (strict mode)
25+
run: |
26+
shellcheck -x compresskit-pdf
27+
shellcheck -x install.sh
28+
shellcheck -x run_tests.sh
2429
2530
- name: Test script permissions
2631
run: |

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ All notable changes to CompressKit will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.1.0] - 2024-12-20
8+
### Added
9+
- Comprehensive security module with improved path validation
10+
- Enhanced input validation for all user-facing functions
11+
- Improved error handling across all components
12+
- Security incident reporting system
13+
- Extended test coverage for security functions
14+
15+
### Fixed
16+
- Critical security vulnerability in safe_path() function that could lead to path traversal
17+
- Inconsistent error handling in compression module
18+
- Potential command injection vulnerabilities in file operations
19+
- Insufficient validation of security-critical parameters
20+
21+
### Changed
22+
- Consolidated security utilities into a single module
23+
- Improved test coverage with dedicated security module tests
24+
- Enhanced documentation with detailed security guides
25+
726
## [1.0.0] - 2024-12-09
827
### Added
928
- Initial release

SECURITY.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,28 @@
44

55
| Version | Supported |
66
| ------- | ------------------ |
7+
| 1.1.x | :white_check_mark: |
78
| 1.0.x | :white_check_mark: |
89

10+
## Security Features
11+
12+
CompressKit implements the following security features:
13+
14+
- **Path Traversal Protection**: All file paths are validated using the `safe_path()` function to prevent directory traversal attacks.
15+
- **Command Execution Protection**: Commands are executed only through `safe_execute()` with a strict allowlist of permitted commands.
16+
- **Input Validation**: All user inputs are validated using dedicated validation functions.
17+
- **Secure File Operations**: All file operations follow secure permissions and include validation.
18+
- **Secure Temporary Files**: Temporary files are created with secure permissions in isolated locations.
19+
- **Error Handling**: Consistent error handling prevents information leakage.
20+
- **Security Incident Reporting**: Security incidents are logged and reported to administrators.
21+
22+
## Recent Security Improvements
23+
24+
- Fixed critical issue in `safe_path()` function that could lead to path traversal vulnerabilities
25+
- Implemented comprehensive security module with improved validation
26+
- Enhanced test coverage for security-critical functions
27+
- Added protection against command injection and URL-encoded path attacks
28+
929
## Reporting a Vulnerability
1030

1131
If you discover a security vulnerability, please:
@@ -16,4 +36,148 @@ If you discover a security vulnerability, please:
1636
4. Allow up to 48 hours for initial response
1737
5. Please keep the vulnerability private until patched
1838

39+
## Security Guidelines for Developers
40+
41+
When contributing to CompressKit:
42+
43+
1. **Always** use `safe_path()` for file path validation
44+
2. **Always** use `safe_execute()` for command execution
45+
3. **Always** validate all user inputs
46+
4. **Always** use secure permissions for files containing sensitive information
47+
5. **Always** implement proper error handling
48+
6. **Never** use `eval` or direct command execution
49+
7. **Never** concatenate user input into paths without validation
50+
1951
Thank you for helping keep CompressKit secure!
52+
53+
## Implementation Examples
54+
55+
### Path Validation with safe_path()
56+
57+
```bash
58+
# INCORRECT - vulnerable to path traversal
59+
process_file() {
60+
local input_file="$1"
61+
cat "$input_file" > output.txt # VULNERABLE!
62+
}
63+
64+
# CORRECT - uses safe_path() to validate
65+
process_file_secure() {
66+
local input_file="$1"
67+
local safe_file
68+
69+
safe_file=$(safe_path "$input_file")
70+
if [ $? -ne 0 ] || [ -z "$safe_file" ]; then
71+
log_error "Invalid file path"
72+
return 1
73+
fi
74+
75+
cat "$safe_file" > output.txt
76+
}
77+
```
78+
79+
### Command Execution with safe_execute()
80+
81+
```bash
82+
# INCORRECT - vulnerable to command injection
83+
run_command() {
84+
local cmd="$1"
85+
eval "$cmd" # VULNERABLE!
86+
}
87+
88+
# CORRECT - uses safe_execute() with allowlisting
89+
run_command_secure() {
90+
local cmd="$1"
91+
safe_execute "$cmd"
92+
}
93+
```
94+
95+
### Input Validation
96+
97+
```bash
98+
# INCORRECT - no input validation
99+
set_compression_level() {
100+
COMPRESSION_LEVEL="$1" # VULNERABLE!
101+
}
102+
103+
# CORRECT - with validation
104+
set_compression_level_secure() {
105+
local level="$1"
106+
107+
# Validate input is a number in valid range
108+
if [[ ! "$level" =~ ^[0-9]+$ ]] || [ "$level" -lt 1 ] || [ "$level" -gt 9 ]; then
109+
log_error "Invalid compression level: $level (must be 1-9)"
110+
return 1
111+
fi
112+
113+
COMPRESSION_LEVEL="$level"
114+
}
115+
```
116+
117+
### Secure File Operations
118+
119+
```bash
120+
# INCORRECT - insecure file creation
121+
create_config() {
122+
echo "setting=value" > config.txt # VULNERABLE!
123+
}
124+
125+
# CORRECT - secure file creation with proper permissions
126+
create_config_secure() {
127+
local config_file
128+
config_file=$(safe_path "${HOME}/.config/compresskit/config.txt")
129+
130+
if [ $? -ne 0 ] || [ -z "$config_file" ]; then
131+
log_error "Invalid config file path"
132+
return 1
133+
fi
134+
135+
# Create directory with secure permissions if needed
136+
local config_dir=$(dirname "$config_file")
137+
if [ ! -d "$config_dir" ]; then
138+
mkdir -p "$config_dir" || {
139+
log_error "Failed to create config directory"
140+
return 1
141+
}
142+
chmod 700 "$config_dir"
143+
fi
144+
145+
# Write file with secure permissions
146+
echo "setting=value" > "$config_file"
147+
chmod 600 "$config_file"
148+
}
149+
```
150+
151+
### Error Handling
152+
153+
```bash
154+
# INCORRECT - poor error handling
155+
compress_file() {
156+
gzip -9 "$1" # VULNERABLE!
157+
}
158+
159+
# CORRECT - with proper error handling
160+
compress_file_secure() {
161+
local input_file="$1"
162+
local safe_file
163+
164+
safe_file=$(safe_path "$input_file")
165+
if [ $? -ne 0 ] || [ -z "$safe_file" ]; then
166+
log_error "Invalid input file path"
167+
return 1
168+
fi
169+
170+
if [ ! -f "$safe_file" ]; then
171+
log_error "Input file does not exist: $safe_file"
172+
return 1
173+
fi
174+
175+
if ! gzip -9 "$safe_file"; then
176+
log_error "Compression failed for: $safe_file"
177+
return 1
178+
fi
179+
180+
log_info "Successfully compressed: $safe_file"
181+
return 0
182+
}
183+
```

docs/ARCHITECTURE.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# CompressKit Architecture
2+
3+
## Overview
4+
5+
CompressKit follows a modular architecture with clear component responsibilities and interactions.
6+
This document outlines the high-level architecture, component interactions, and design philosophy.
7+
8+
## Component Diagram
9+
10+
```
11+
┌─────────────────────┐ ┌─────────────────┐ ┌────────────────────┐
12+
│ compresskit-pdf │────▶│ Core Library │────▶│ Compress Engine │
13+
└─────────────────────┘ └─────────────────┘ └────────────────────┘
14+
│ │ │
15+
▼ ▼ ▼
16+
┌─────────────────────┐ ┌─────────────────┐ ┌────────────────────┐
17+
│ UI Layer │◀───▶│ Config Manager │ │ Error Handler │
18+
└─────────────────────┘ └─────────────────┘ └────────────────────┘
19+
│ │ │
20+
└─────────────────────────┼────────────────────────┘
21+
22+
┌─────────────────┐
23+
│ Logging System │
24+
└─────────────────┘
25+
```
26+
27+
## Component Responsibilities
28+
29+
### 1. Entry Points
30+
31+
- **compresskit-pdf**: Main executable script that provides the command-line interface
32+
- **compresskit**: Simplified interface for basic operations
33+
34+
### 2. Core Components
35+
36+
- **lib/core.sh**: Central integration layer for all components
37+
- **lib/config_manager.sh**: Centralized configuration management
38+
- **lib/compress.sh**: PDF compression implementation
39+
- **lib/error_handler.sh**: Error handling and recovery mechanisms
40+
- **lib/logger.sh**: Logging system
41+
- **lib/ui.sh**: User interface components
42+
43+
### 3. Security Layer
44+
45+
- **lib/secure_utils.sh**: Security utilities for safe file operations
46+
47+
## Data Flow
48+
49+
1. User invokes `compresskit-pdf` with command-line arguments
50+
2. Core library validates input and initializes the environment
51+
3. Configuration is loaded from the config manager
52+
4. Compression operation is performed by the compress engine
53+
5. Progress and results are displayed via the UI layer
54+
6. Errors are captured and handled by the error handler
55+
7. All operations are logged by the logging system
56+
57+
## Security Considerations
58+
59+
CompressKit implements several security measures:
60+
61+
- Path traversal prevention through `safe_path()` validation
62+
- Secure temporary file handling
63+
- Input validation and sanitization
64+
- Proper permission management
65+
- Command injection prevention
66+
67+
## Configuration Flow
68+
69+
1. Default configuration paths defined in `config_manager.sh`
70+
2. Configuration values loaded by `config.sh`
71+
3. Components request configuration via standard functions
72+
73+
## Error Handling
74+
75+
CompressKit uses a centralized error handling approach:
76+
77+
1. Functions return error codes to indicate success/failure
78+
2. Error conditions are logged and reported to the user
79+
3. Recovery mechanisms attempt to handle certain error conditions
80+
4. Detailed error information is stored in log files
81+
82+
## Logging System
83+
84+
The logging system provides:
85+
86+
- Multiple log levels (ORACLE/DEBUG, HERO/INFO, OMEN/WARNING, DOOM/ERROR)
87+
- Timestamped log entries
88+
- Log rotation to prevent excessive log file growth
89+
- Secure log file handling with proper permissions

0 commit comments

Comments
 (0)