Skip to content

feat: add warning for routes registered without a sanitizer function#93

Merged
Suhaibinator merged 1 commit intomainfrom
sanitizer
Jul 20, 2025
Merged

feat: add warning for routes registered without a sanitizer function#93
Suhaibinator merged 1 commit intomainfrom
sanitizer

Conversation

@Suhaibinator
Copy link
Copy Markdown
Owner

No description provided.

@Suhaibinator Suhaibinator requested a review from Copilot July 20, 2025 00:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a security warning feature that alerts developers when routes are registered without sanitizer functions. This helps identify potential security vulnerabilities where user input may not be properly sanitized before processing.

  • Adds warning logging when routes are registered without sanitizer functions
  • Imports the go.uber.org/zap logging library to support structured logging

Comment thread pkg/router/route.go
Comment on lines +223 to +231
r.logger.Warn("Route registered without sanitizer function",
zap.String("path", route.Path),
zap.Strings("methods", func() []string {
methods := make([]string, len(route.Methods))
for i, method := range route.Methods {
methods[i] = string(method)
}
return methods
}()),
Copy link

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

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

The anonymous function creates a new slice on every route registration. Consider pre-converting the methods slice outside the zap.Strings call to avoid unnecessary allocations during logging.

Suggested change
r.logger.Warn("Route registered without sanitizer function",
zap.String("path", route.Path),
zap.Strings("methods", func() []string {
methods := make([]string, len(route.Methods))
for i, method := range route.Methods {
methods[i] = string(method)
}
return methods
}()),
// Pre-convert route.Methods to a string slice
methods := make([]string, len(route.Methods))
for i, method := range route.Methods {
methods[i] = string(method)
}
r.logger.Warn("Route registered without sanitizer function",
zap.String("path", route.Path),
zap.Strings("methods", methods),

Copilot uses AI. Check for mistakes.
Comment thread pkg/router/route.go
zap.String("path", route.Path),
zap.Strings("methods", func() []string {
methods := make([]string, len(route.Methods))
for i, method := range route.Methods {
Copy link

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

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

[nitpick] The inline anonymous function with loop logic makes the logging call harder to read. Extract this conversion logic to a separate helper function or perform the conversion before the logging statement.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Jul 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.18%. Comparing base (141fbf1) to head (bf5b329).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   97.17%   97.18%   +0.01%     
==========================================
  Files          18       18              
  Lines        2370     2379       +9     
==========================================
+ Hits         2303     2312       +9     
  Misses         55       55              
  Partials       12       12              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Suhaibinator Suhaibinator merged commit 6dd6bda into main Jul 20, 2025
11 checks passed
@Suhaibinator Suhaibinator deleted the sanitizer branch July 20, 2025 00:08
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.

2 participants