File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -539,7 +539,7 @@ public function id(?array $ids = null): UntaggedResponse
539539 $ token = '( ' ;
540540
541541 foreach ($ ids as $ id ) {
542- $ token .= '" ' .$ id .'" ' ;
542+ $ token .= '" ' .Str:: escape ( $ id) .'" ' ;
543543 }
544544
545545 $ token = rtrim ($ token ).') ' ;
Original file line number Diff line number Diff line change 648648 expect ($ response ->type ()->is ('ID ' ))->toBeTrue ();
649649});
650650
651+ test ('id escapes special characters to prevent command injection ' , function () {
652+ $ stream = new FakeStream ;
653+ $ stream ->open ();
654+
655+ $ stream ->feed ([
656+ '* OK Welcome to IMAP ' ,
657+ '* ID NIL ' ,
658+ 'TAG1 OK ID completed ' ,
659+ ]);
660+
661+ $ connection = new ImapConnection ($ stream );
662+ $ connection ->connect ('imap.example.com ' );
663+
664+ $ connection ->id ([
665+ 'name ' => 'Evil"Client ' ,
666+ 'version ' => "1.0 \r\nLOGOUT " ,
667+ 'vendor ' => 'Test \\Vendor ' ,
668+ ]);
669+
670+ $ stream ->assertWritten ('TAG1 ID ("Evil \\"Client" "1.0LOGOUT" "Test \\\\Vendor") ' );
671+ });
672+
651673test ('expunge ' , function () {
652674 $ stream = new FakeStream ;
653675 $ stream ->open ();
You can’t perform that action at this time.
0 commit comments