mirror of
https://github.com/acedanger/shell.git
synced 2025-12-05 21:40:12 -08:00
formatting
This commit is contained in:
@@ -5,12 +5,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Pre-Development Security Checklist
|
## Pre-Development Security Checklist
|
||||||
|
|
||||||
### Script Header Requirements
|
### Script Header Requirements
|
||||||
|
|
||||||
- [ ] Includes comprehensive header with author, version, and security notes
|
- [ ] Includes comprehensive header with author, version, and security notes
|
||||||
- [ ] Documents all parameters and their validation requirements
|
- [ ] Documents all parameters and their validation requirements
|
||||||
- [ ] Specifies required permissions and security considerations
|
- [ ] Specifies required permissions and security considerations
|
||||||
- [ ] Includes usage examples with security implications
|
- [ ] Includes usage examples with security implications
|
||||||
|
|
||||||
### Initial Security Setup
|
### Initial Security Setup
|
||||||
|
|
||||||
- [ ] Uses `set -euo pipefail` for strict error handling
|
- [ ] Uses `set -euo pipefail` for strict error handling
|
||||||
- [ ] Defines readonly constants for sensitive paths and configurations
|
- [ ] Defines readonly constants for sensitive paths and configurations
|
||||||
- [ ] Implements cleanup function with proper trap handling
|
- [ ] Implements cleanup function with proper trap handling
|
||||||
@@ -19,6 +21,7 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Input Validation and Sanitization
|
## Input Validation and Sanitization
|
||||||
|
|
||||||
### Command Line Arguments
|
### Command Line Arguments
|
||||||
|
|
||||||
- [ ] Validates all positional parameters
|
- [ ] Validates all positional parameters
|
||||||
- [ ] Checks parameter count and types
|
- [ ] Checks parameter count and types
|
||||||
- [ ] Sanitizes file paths to prevent directory traversal
|
- [ ] Sanitizes file paths to prevent directory traversal
|
||||||
@@ -26,12 +29,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
- [ ] Rejects dangerous characters in string inputs
|
- [ ] Rejects dangerous characters in string inputs
|
||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
- [ ] Validates all used environment variables
|
- [ ] Validates all used environment variables
|
||||||
- [ ] Provides secure defaults for missing variables
|
- [ ] Provides secure defaults for missing variables
|
||||||
- [ ] Sanitizes environment-derived paths and commands
|
- [ ] Sanitizes environment-derived paths and commands
|
||||||
- [ ] Documents required environment setup
|
- [ ] Documents required environment setup
|
||||||
|
|
||||||
### File and Directory Operations
|
### File and Directory Operations
|
||||||
|
|
||||||
- [ ] Verifies file existence before operations
|
- [ ] Verifies file existence before operations
|
||||||
- [ ] Checks file permissions and ownership
|
- [ ] Checks file permissions and ownership
|
||||||
- [ ] Validates file paths for traversal attempts
|
- [ ] Validates file paths for traversal attempts
|
||||||
@@ -41,18 +46,21 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Variable Usage and Quoting
|
## Variable Usage and Quoting
|
||||||
|
|
||||||
### Variable Declaration
|
### Variable Declaration
|
||||||
|
|
||||||
- [ ] Uses `readonly` for constants
|
- [ ] Uses `readonly` for constants
|
||||||
- [ ] Uses `local` for function variables
|
- [ ] Uses `local` for function variables
|
||||||
- [ ] Initializes all variables before use
|
- [ ] Initializes all variables before use
|
||||||
- [ ] Uses descriptive variable names
|
- [ ] Uses descriptive variable names
|
||||||
|
|
||||||
### Variable Expansion
|
### Variable Expansion
|
||||||
|
|
||||||
- [ ] **CRITICAL:** All variables quoted in command contexts: `"$VARIABLE"`
|
- [ ] **CRITICAL:** All variables quoted in command contexts: `"$VARIABLE"`
|
||||||
- [ ] Array expansions properly quoted: `"${ARRAY[@]}"`
|
- [ ] Array expansions properly quoted: `"${ARRAY[@]}"`
|
||||||
- [ ] Parameter expansions use braces: `"${VAR:-default}"`
|
- [ ] Parameter expansions use braces: `"${VAR:-default}"`
|
||||||
- [ ] Command substitutions properly quoted: `RESULT="$(command)"`
|
- [ ] Command substitutions properly quoted: `RESULT="$(command)"`
|
||||||
|
|
||||||
### Dangerous Patterns to Avoid
|
### Dangerous Patterns to Avoid
|
||||||
|
|
||||||
- [ ] **NEVER:** Unquoted variables in commands: `command $VAR`
|
- [ ] **NEVER:** Unquoted variables in commands: `command $VAR`
|
||||||
- [ ] **NEVER:** Unquoted variables in file operations: `rm $FILE`
|
- [ ] **NEVER:** Unquoted variables in file operations: `rm $FILE`
|
||||||
- [ ] **NEVER:** Unquoted variables in loops: `for item in $LIST`
|
- [ ] **NEVER:** Unquoted variables in loops: `for item in $LIST`
|
||||||
@@ -61,18 +69,21 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Command Execution Security
|
## Command Execution Security
|
||||||
|
|
||||||
### External Commands
|
### External Commands
|
||||||
|
|
||||||
- [ ] Validates command existence before execution
|
- [ ] Validates command existence before execution
|
||||||
- [ ] Uses full paths for critical system commands
|
- [ ] Uses full paths for critical system commands
|
||||||
- [ ] Escapes or validates all command arguments
|
- [ ] Escapes or validates all command arguments
|
||||||
- [ ] Handles command failures appropriately
|
- [ ] Handles command failures appropriately
|
||||||
|
|
||||||
### Dangerous Command Patterns
|
### Dangerous Command Patterns
|
||||||
|
|
||||||
- [ ] **AVOID:** `eval` statements (if used, sanitize inputs extensively)
|
- [ ] **AVOID:** `eval` statements (if used, sanitize inputs extensively)
|
||||||
- [ ] **AVOID:** `source` or `.` with user-controlled paths
|
- [ ] **AVOID:** `source` or `.` with user-controlled paths
|
||||||
- [ ] **AVOID:** `curl | bash` or `wget | sh` patterns
|
- [ ] **AVOID:** `curl | bash` or `wget | sh` patterns
|
||||||
- [ ] **AVOID:** Uncontrolled `find -exec` operations
|
- [ ] **AVOID:** Uncontrolled `find -exec` operations
|
||||||
|
|
||||||
### Privilege Escalation
|
### Privilege Escalation
|
||||||
|
|
||||||
- [ ] Minimizes `sudo` usage to specific commands
|
- [ ] Minimizes `sudo` usage to specific commands
|
||||||
- [ ] Uses service-specific users instead of root where possible
|
- [ ] Uses service-specific users instead of root where possible
|
||||||
- [ ] Validates commands before privilege escalation
|
- [ ] Validates commands before privilege escalation
|
||||||
@@ -81,6 +92,7 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Network and Remote Operations
|
## Network and Remote Operations
|
||||||
|
|
||||||
### Download Security
|
### Download Security
|
||||||
|
|
||||||
- [ ] **REQUIRED:** Download to temporary location first
|
- [ ] **REQUIRED:** Download to temporary location first
|
||||||
- [ ] **RECOMMENDED:** Verify checksums or signatures
|
- [ ] **RECOMMENDED:** Verify checksums or signatures
|
||||||
- [ ] **REQUIRED:** Validate content before execution
|
- [ ] **REQUIRED:** Validate content before execution
|
||||||
@@ -88,6 +100,7 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
- [ ] Implement timeout and retry logic
|
- [ ] Implement timeout and retry logic
|
||||||
|
|
||||||
### API and Service Interactions
|
### API and Service Interactions
|
||||||
|
|
||||||
- [ ] Validates API responses before processing
|
- [ ] Validates API responses before processing
|
||||||
- [ ] Uses authentication tokens securely
|
- [ ] Uses authentication tokens securely
|
||||||
- [ ] Implements proper error handling for network failures
|
- [ ] Implements proper error handling for network failures
|
||||||
@@ -96,12 +109,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Database and File System Security
|
## Database and File System Security
|
||||||
|
|
||||||
### Database Operations
|
### Database Operations
|
||||||
|
|
||||||
- [ ] Uses parameterized queries or proper escaping
|
- [ ] Uses parameterized queries or proper escaping
|
||||||
- [ ] Validates database paths and names
|
- [ ] Validates database paths and names
|
||||||
- [ ] Implements backup and recovery procedures
|
- [ ] Implements backup and recovery procedures
|
||||||
- [ ] Handles database locks and corruption gracefully
|
- [ ] Handles database locks and corruption gracefully
|
||||||
|
|
||||||
### File System Security
|
### File System Security
|
||||||
|
|
||||||
- [ ] Sets appropriate file permissions (644 for files, 755 for directories)
|
- [ ] Sets appropriate file permissions (644 for files, 755 for directories)
|
||||||
- [ ] Validates ownership before operations
|
- [ ] Validates ownership before operations
|
||||||
- [ ] Implements secure temporary file creation
|
- [ ] Implements secure temporary file creation
|
||||||
@@ -110,12 +125,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Service and Container Management
|
## Service and Container Management
|
||||||
|
|
||||||
### Service Operations
|
### Service Operations
|
||||||
|
|
||||||
- [ ] Validates service state before operations
|
- [ ] Validates service state before operations
|
||||||
- [ ] Implements proper start/stop sequences
|
- [ ] Implements proper start/stop sequences
|
||||||
- [ ] Handles service failures gracefully
|
- [ ] Handles service failures gracefully
|
||||||
- [ ] Logs service management activities
|
- [ ] Logs service management activities
|
||||||
|
|
||||||
### Container Security
|
### Container Security
|
||||||
|
|
||||||
- [ ] Validates container names and IDs
|
- [ ] Validates container names and IDs
|
||||||
- [ ] Uses specific image tags instead of 'latest'
|
- [ ] Uses specific image tags instead of 'latest'
|
||||||
- [ ] Implements proper volume and network security
|
- [ ] Implements proper volume and network security
|
||||||
@@ -124,12 +141,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Error Handling and Logging
|
## Error Handling and Logging
|
||||||
|
|
||||||
### Error Handling Requirements
|
### Error Handling Requirements
|
||||||
|
|
||||||
- [ ] Implements comprehensive error handling for all operations
|
- [ ] Implements comprehensive error handling for all operations
|
||||||
- [ ] Uses appropriate exit codes (0 for success, 1-255 for various errors)
|
- [ ] Uses appropriate exit codes (0 for success, 1-255 for various errors)
|
||||||
- [ ] Provides meaningful error messages
|
- [ ] Provides meaningful error messages
|
||||||
- [ ] Implements cleanup on error conditions
|
- [ ] Implements cleanup on error conditions
|
||||||
|
|
||||||
### Logging Security
|
### Logging Security
|
||||||
|
|
||||||
- [ ] Logs security-relevant events
|
- [ ] Logs security-relevant events
|
||||||
- [ ] Avoids logging sensitive information (passwords, tokens)
|
- [ ] Avoids logging sensitive information (passwords, tokens)
|
||||||
- [ ] Implements log rotation and retention policies
|
- [ ] Implements log rotation and retention policies
|
||||||
@@ -138,12 +157,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Testing and Validation
|
## Testing and Validation
|
||||||
|
|
||||||
### Security Testing
|
### Security Testing
|
||||||
|
|
||||||
- [ ] **REQUIRED:** Run `bash -n script.sh` for syntax validation
|
- [ ] **REQUIRED:** Run `bash -n script.sh` for syntax validation
|
||||||
- [ ] **RECOMMENDED:** Use ShellCheck for security analysis
|
- [ ] **RECOMMENDED:** Use ShellCheck for security analysis
|
||||||
- [ ] Test with various input combinations including edge cases
|
- [ ] Test with various input combinations including edge cases
|
||||||
- [ ] Test error conditions and recovery procedures
|
- [ ] Test error conditions and recovery procedures
|
||||||
|
|
||||||
### Manual Security Review
|
### Manual Security Review
|
||||||
|
|
||||||
- [ ] Review all variable usage for proper quoting
|
- [ ] Review all variable usage for proper quoting
|
||||||
- [ ] Verify all file operations use absolute paths
|
- [ ] Verify all file operations use absolute paths
|
||||||
- [ ] Check for potential race conditions
|
- [ ] Check for potential race conditions
|
||||||
@@ -152,12 +173,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Documentation Requirements
|
## Documentation Requirements
|
||||||
|
|
||||||
### Security Documentation
|
### Security Documentation
|
||||||
|
|
||||||
- [ ] Document all security assumptions
|
- [ ] Document all security assumptions
|
||||||
- [ ] List required permissions and privileges
|
- [ ] List required permissions and privileges
|
||||||
- [ ] Document potential security risks
|
- [ ] Document potential security risks
|
||||||
- [ ] Provide secure usage examples
|
- [ ] Provide secure usage examples
|
||||||
|
|
||||||
### Operational Security
|
### Operational Security
|
||||||
|
|
||||||
- [ ] Document deployment security requirements
|
- [ ] Document deployment security requirements
|
||||||
- [ ] Specify required environment security
|
- [ ] Specify required environment security
|
||||||
- [ ] Document integration security considerations
|
- [ ] Document integration security considerations
|
||||||
@@ -166,12 +189,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Code Review Checklist
|
## Code Review Checklist
|
||||||
|
|
||||||
### Pre-Commit Review
|
### Pre-Commit Review
|
||||||
|
|
||||||
- [ ] All variables properly quoted
|
- [ ] All variables properly quoted
|
||||||
- [ ] No unvalidated user inputs
|
- [ ] No unvalidated user inputs
|
||||||
- [ ] Appropriate error handling implemented
|
- [ ] Appropriate error handling implemented
|
||||||
- [ ] Security documentation updated
|
- [ ] Security documentation updated
|
||||||
|
|
||||||
### Peer Review Requirements
|
### Peer Review Requirements
|
||||||
|
|
||||||
- [ ] Security-critical changes reviewed by security-aware developer
|
- [ ] Security-critical changes reviewed by security-aware developer
|
||||||
- [ ] Privilege usage justified and documented
|
- [ ] Privilege usage justified and documented
|
||||||
- [ ] External integrations reviewed for security implications
|
- [ ] External integrations reviewed for security implications
|
||||||
@@ -180,12 +205,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Deployment Security
|
## Deployment Security
|
||||||
|
|
||||||
### Production Deployment
|
### Production Deployment
|
||||||
|
|
||||||
- [ ] Environment variables secured and validated
|
- [ ] Environment variables secured and validated
|
||||||
- [ ] File permissions set appropriately
|
- [ ] File permissions set appropriately
|
||||||
- [ ] Service accounts configured with minimal privileges
|
- [ ] Service accounts configured with minimal privileges
|
||||||
- [ ] Logging and monitoring configured
|
- [ ] Logging and monitoring configured
|
||||||
|
|
||||||
### Security Monitoring
|
### Security Monitoring
|
||||||
|
|
||||||
- [ ] Failed authentication attempts logged
|
- [ ] Failed authentication attempts logged
|
||||||
- [ ] Privilege escalation attempts logged
|
- [ ] Privilege escalation attempts logged
|
||||||
- [ ] Unusual file access patterns monitored
|
- [ ] Unusual file access patterns monitored
|
||||||
@@ -194,12 +221,14 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
## Maintenance and Updates
|
## Maintenance and Updates
|
||||||
|
|
||||||
### Regular Security Maintenance
|
### Regular Security Maintenance
|
||||||
|
|
||||||
- [ ] Review and update security dependencies
|
- [ ] Review and update security dependencies
|
||||||
- [ ] Update security documentation
|
- [ ] Update security documentation
|
||||||
- [ ] Review and rotate secrets and tokens
|
- [ ] Review and rotate secrets and tokens
|
||||||
- [ ] Update security testing procedures
|
- [ ] Update security testing procedures
|
||||||
|
|
||||||
### Security Incident Response
|
### Security Incident Response
|
||||||
|
|
||||||
- [ ] Document security incident procedures
|
- [ ] Document security incident procedures
|
||||||
- [ ] Implement security rollback procedures
|
- [ ] Implement security rollback procedures
|
||||||
- [ ] Define security escalation paths
|
- [ ] Define security escalation paths
|
||||||
@@ -209,7 +238,8 @@ This checklist should be used for all new shell scripts and when modifying exist
|
|||||||
|
|
||||||
## Common Security Anti-Patterns
|
## Common Security Anti-Patterns
|
||||||
|
|
||||||
### ❌ DO NOT DO THIS:
|
### ❌ DO NOT DO THIS
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Unquoted variable in command
|
# Unquoted variable in command
|
||||||
docker pull $IMAGE
|
docker pull $IMAGE
|
||||||
@@ -230,7 +260,8 @@ chmod 777 /path/to/file
|
|||||||
rm -rf $USER_PROVIDED_PATH
|
rm -rf $USER_PROVIDED_PATH
|
||||||
```
|
```
|
||||||
|
|
||||||
### ✅ DO THIS INSTEAD:
|
### ✅ DO THIS INSTEAD
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Quoted variable in command
|
# Quoted variable in command
|
||||||
docker pull "$IMAGE"
|
docker pull "$IMAGE"
|
||||||
|
|||||||
Reference in New Issue
Block a user