@@ -677,6 +677,24 @@ public function it_will_submit_form_and_follow_custom_redirect_with_success()
677677 $ this ->assertStringContainsString ('<div class="analytics"></div> ' , $ output );
678678 }
679679
680+ #[Test]
681+ public function it_does_not_follow_external_redirect_on_success ()
682+ {
683+ $ this ->assertEmpty (Form::find ('contact ' )->submissions ());
684+
685+ $ this
686+ ->from ('/contact ' )
687+ ->post ('/!/forms/contact ' , [
688+ 'email ' => 'san@holo.com ' ,
689+ 'message ' => 'hello ' ,
690+ '_redirect ' => 'https://evil.com/phishing ' ,
691+ ])
692+ ->assertSessionHasNoErrors ()
693+ ->assertLocation ('/contact ' );
694+
695+ $ this ->assertCount (1 , Form::find ('contact ' )->submissions ());
696+ }
697+
680698 #[Test]
681699 public function it_will_submit_form_with_honeypot_filled_and_render_fake_success ()
682700 {
@@ -753,6 +771,29 @@ public function it_wont_submit_form_and_follow_custom_redirect_with_errors()
753771 $ this ->assertEmpty ($ success [1 ]);
754772 }
755773
774+ #[Test]
775+ public function it_does_not_follow_external_error_redirect ()
776+ {
777+ $ this ->assertEmpty (Form::find ('contact ' )->submissions ());
778+
779+ Event::listen (function (\Statamic \Events \FormSubmitted $ event ) {
780+ throw ValidationException::withMessages (['custom ' => 'This is a custom message ' ]);
781+ });
782+
783+ $ this
784+ ->from ('/contact ' )
785+ ->post ('/!/forms/contact ' , [
786+ '_error_redirect ' => 'https://evil.com/phishing ' ,
787+ 'name ' => 'Hansolo ' ,
788+ 'email ' => 'san@holo.com ' ,
789+ 'message ' => 'hello ' ,
790+ ])
791+ ->assertSessionHasErrors (['custom ' ], null , 'form.contact ' )
792+ ->assertLocation ('/contact ' );
793+
794+ $ this ->assertCount (0 , Form::find ('contact ' )->submissions ());
795+ }
796+
756797 #[Test]
757798 public function it_will_use_redirect_query_param_off_url ()
758799 {
0 commit comments