ValidateStdinInput validates stdin content for security This is a wrapper around existing security validation
(content []byte)
| 133 | // ValidateStdinInput validates stdin content for security |
| 134 | // This is a wrapper around existing security validation |
| 135 | func ValidateStdinInput(content []byte) error { |
| 136 | // Basic validation: check if content looks like SQL |
| 137 | if len(content) == 0 { |
| 138 | return fmt.Errorf("empty input") |
| 139 | } |
| 140 | |
| 141 | // Size check (already done in ReadFromStdin, but double-check) |
| 142 | if len(content) > MaxStdinSize { |
| 143 | return fmt.Errorf("input too large: %d bytes (max %d)", len(content), MaxStdinSize) |
| 144 | } |
| 145 | |
| 146 | // Additional validation: ensure it's not binary data |
| 147 | // Check for null bytes (common in binary files) |
| 148 | for i := 0; i < len(content) && i < 512; i++ { |
| 149 | if content[i] == 0 { |
| 150 | return fmt.Errorf("binary data detected in input") |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return nil |
| 155 | } |
| 156 | |
| 157 | // DetectInputMode determines the input mode based on arguments and stdin state |
| 158 | // Returns: (useStdin bool, inputArg string, error) |