Skip to content

Conversation

vishr
Copy link
Member

@vishr vishr commented Sep 16, 2025

Summary

Improves code readability and maintainability of the secure middleware with better user guidance.

Changes:

  1. Refactor HSTS header construction - Replace nested fmt.Sprintf with slice building and strings.Join for clearer logic
  2. Add X-XSS-Protection deprecation notice - Document that CSP is recommended over the deprecated header
  3. Clean up imports - Remove unused fmt import

Benefits:

  • Cleaner, more maintainable HSTS directive building
  • Better user guidance about modern security practices
  • Improved code readability

Test plan

  • All existing tests pass
  • Linting passes
  • No behavioral changes to security headers

Fixes #2799

🤖 Generated with Claude Code

- Refactor HSTS header construction using slice and strings.Join
  for better readability instead of nested fmt.Sprintf
- Add deprecation notice for X-XSS-Protection header with CSP recommendation
- Remove unused fmt import

Improves code maintainability and provides better user guidance.

Fixes #2799

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link
Contributor

@aldas aldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these strings.Join(directives, "; ") calculation could be precalculated, between 109 and 110 lines

return func(next echo.HandlerFunc) echo.HandlerFunc {
// here
		return func(c echo.Context) error {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Further improve readability and maintainability of middleware/secure.go
3 participants