Skip to content

feat: introduce CanBeMasked, SecurityStringer type for sensitive data handling #1531

@saitofun

Description

@saitofun

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

To enhance security, we should introduce a mechanism to automatically mask or redact sensitive fields (e.g., credentials, tokens, or PII) during logging and serialization.

eg:

type SecurityStriner interface{
	SecurityString() string
}
type Password string

func (Password) SecurityString() string {
	return "--masked--"
}

// in zap library
func SecurityString(key string) Field{
	return String(key, "--masked--"
}

func Any(key string, v any) Field {
	if key == "passowrd" || key == "passwd" { // ... or other sensitive key
		return zap.String(key, "--masked--")
	}

	swtich v.(type) {
	//...
	case SecurityStringer:
		return zap.String(key, "--masked--")
	//...
	}
}

Describe alternatives you've considered
Security

Is this a breaking change?
No

Additional context
No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions