File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed
Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -201,6 +201,24 @@ var _ = Describe("Plugin connection", func() {
201201 s .Cleanup ()
202202 })
203203
204+ It ("should reject plugins with an invalid name" , func () {
205+ var (
206+ validPlugin = & mockPlugin {
207+ name : "abcd-0123+EFGH_4567.ijkl" ,
208+ idx : "05" ,
209+ }
210+ invalidPlugin = & mockPlugin {
211+ name : "foo,bar" ,
212+ idx : "10" ,
213+ }
214+ )
215+
216+ s .Startup ()
217+
218+ Expect (validPlugin .Start (s .dir )).To (Succeed ())
219+ Expect (invalidPlugin .Start (s .dir )).ToNot (Succeed ())
220+ })
221+
204222 It ("should configure the plugin" , func () {
205223 var (
206224 plugin = s .plugins [0 ]
Original file line number Diff line number Diff line change @@ -435,9 +435,9 @@ func (p *plugin) qualifiedName() string {
435435// RegisterPlugin handles the plugin's registration request.
436436func (p * plugin ) RegisterPlugin (ctx context.Context , req * RegisterPluginRequest ) (* RegisterPluginResponse , error ) {
437437 if p .isExternal () {
438- if req .PluginName == "" {
439- p .regC <- fmt .Errorf ("plugin %q registered with an empty name" , p . qualifiedName () )
440- return & RegisterPluginResponse {}, errors . New ("invalid (empty) plugin name" )
438+ if err := api . CheckPluginName ( req .PluginName ); err != nil {
439+ p .regC <- fmt .Errorf ("plugin registered with an invalid name: %w " , err )
440+ return & RegisterPluginResponse {}, fmt . Errorf ("invalid plugin name: %w" , err )
441441 }
442442 if err := api .CheckPluginIndex (req .PluginIdx ); err != nil {
443443 p .regC <- fmt .Errorf ("plugin %q registered with an invalid index: %w" , req .PluginName , err )
Original file line number Diff line number Diff line change 1717package api
1818
1919import (
20+ "errors"
2021 "fmt"
2122 "strings"
2223)
@@ -57,3 +58,23 @@ func CheckPluginIndex(idx string) error {
5758 }
5859 return nil
5960}
61+
62+ // CheckPluginName verifies that a plugin name is not empty and only contains
63+ // characters from the set [a-zA-Z0-9_.+-].
64+ func CheckPluginName (name string ) error {
65+ if name == "" {
66+ return errors .New ("invalid plugin name: name is empty" )
67+ }
68+
69+ for _ , r := range name {
70+ switch {
71+ case 'a' <= r && r <= 'z' , 'A' <= r && r <= 'Z' :
72+ case '0' <= r && r <= '9' :
73+ case r == '-' , r == '_' , r == '.' , r == '+' :
74+ default :
75+ return fmt .Errorf ("invalid plugin name %q: contains invalid character %q" , name , r )
76+ }
77+ }
78+
79+ return nil
80+ }
You can’t perform that action at this time.
0 commit comments