Skip to content

Commit 94766bb

Browse files
committed
Enhance handler name validation to enforce strict snake_case format
1 parent c24952c commit 94766bb

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/hooks/core/config_validator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def self.valid_handler_name?(handler_name)
125125
# Must not be empty or only whitespace
126126
return false if handler_name.strip.empty?
127127

128-
# Must match a safe pattern: alphanumeric + underscore, starting with lowercase
129-
return false unless handler_name.match?(/\A[a-z][a-z0-9_]*\z/)
128+
# Must match strict snake_case pattern: starts with lowercase, no trailing/consecutive underscores
129+
return false unless handler_name.match?(/\A[a-z][a-z0-9]*(?:_[a-z0-9]+)*\z/)
130130

131131
# Convert to PascalCase for security check (since DANGEROUS_CLASSES uses PascalCase)
132132
pascal_case_name = handler_name.split("_").map(&:capitalize).join("")

spec/unit/lib/hooks/core/config_validator_security_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
4949
{ path: "/webhook", handler: "handler test" }, # spaces
5050
{ path: "/webhook", handler: "handler\ntest" }, # newlines
5151
{ path: "/webhook", handler: "handlerTest" }, # camelCase
52-
{ path: "/webhook", handler: "HandlerTest" } # PascalCase
52+
{ path: "/webhook", handler: "HandlerTest" }, # PascalCase
53+
{ path: "/webhook", handler: "handler_" }, # trailing underscore
54+
{ path: "/webhook", handler: "my__handler" }, # consecutive underscores
55+
{ path: "/webhook", handler: "handler__test" } # consecutive underscores in middle
5356
]
5457

5558
invalid_configs.each do |config|

0 commit comments

Comments
 (0)