mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-23 06:47:26 +00:00
chore(security,refactor): extract sanitization and improve code quality (#41)
* chore(security,refactor): extract sanitization and improve code quality
- [x] Extract sanitization functions to dedicated sanitization.go module
- [x] Add comprehensive golangci-lint v2 configuration with security rules
- [x] Replace interface{} with any type throughout codebase
- [x] Add admin API authentication security warning
- [x] Extract WebSocket and stats streaming constants
- [x] Add best-effort error handling comments for resource cleanup
- [x] Expand sensitive field patterns for improved PII redaction
- [x] Simplify safety checks and remove redundant nil validations
- [x] Improve test coverage for password field redaction patterns
* refactor: replace interface{} with any type alias
- [x] Replace all `map[string]interface{}` with `map[string]any`
- [x] Replace all `interface{}` with `any` in function signatures and type definitions
- [x] Update sync.Pool New function returns from `interface{}` to `any`
- [x] Add package documentation comments to 8 package files
- [x] Update type assertions and casts to work with `any` type
This commit is contained in:
@@ -27,7 +27,7 @@ func TestEventsSecurityTestSuite(t *testing.T) {
|
||||
// TestEventCleanerSQLInjection tests various SQL injection attempts in the event cleaner
|
||||
func (suite *EventsSecurityTestSuite) TestEventCleanerSQLInjection() {
|
||||
tests := []struct {
|
||||
clearDays interface{}
|
||||
clearDays any
|
||||
name string
|
||||
description string
|
||||
expectError bool
|
||||
@@ -175,7 +175,7 @@ func (suite *EventsSecurityTestSuite) TestEventCleanerParameterizedQueries() {
|
||||
|
||||
// TestEventCleanerConcurrentSQLInjection tests SQL injection under concurrent conditions
|
||||
func (suite *EventsSecurityTestSuite) TestEventCleanerConcurrentSQLInjection() {
|
||||
maliciousInputs := []interface{}{
|
||||
maliciousInputs := []any{
|
||||
"1'; DROP TABLE events; --",
|
||||
"1 OR 1=1",
|
||||
"'; TRUNCATE events; --",
|
||||
@@ -185,7 +185,7 @@ func (suite *EventsSecurityTestSuite) TestEventCleanerConcurrentSQLInjection() {
|
||||
done := make(chan error, len(maliciousInputs))
|
||||
|
||||
for _, input := range maliciousInputs {
|
||||
go func(val interface{}) {
|
||||
go func(val any) {
|
||||
err := validateClearDaysInput(val)
|
||||
done <- err
|
||||
}(input)
|
||||
@@ -202,7 +202,7 @@ func (suite *EventsSecurityTestSuite) TestEventCleanerConcurrentSQLInjection() {
|
||||
// TestEventCleanerInputSanitization tests input sanitization effectiveness
|
||||
func (suite *EventsSecurityTestSuite) TestEventCleanerInputSanitization() {
|
||||
tests := []struct {
|
||||
input interface{}
|
||||
input any
|
||||
name string
|
||||
expected int
|
||||
hasError bool
|
||||
@@ -279,7 +279,7 @@ func (suite *EventsSecurityTestSuite) TestEventCleanerDatabaseInteraction() {
|
||||
// Helper functions that should be implemented in the main codebase
|
||||
|
||||
// validateClearDaysInput validates and sanitizes the clearDays input
|
||||
func validateClearDaysInput(input interface{}) error {
|
||||
func validateClearDaysInput(input any) error {
|
||||
// This function should be implemented in the main codebase
|
||||
// to validate clearDays input before using it in SQL queries
|
||||
|
||||
@@ -319,7 +319,7 @@ func validateClearDaysInput(input interface{}) error {
|
||||
}
|
||||
|
||||
// sanitizeAndValidateClearDays sanitizes and validates the input, returning the clean integer
|
||||
func sanitizeAndValidateClearDays(input interface{}) (int, error) {
|
||||
func sanitizeAndValidateClearDays(input any) (int, error) {
|
||||
err := validateClearDaysInput(input)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Reference in New Issue
Block a user