@@ -736,3 +736,67 @@ async def test_samesite_invalid_config():
736736 )
737737 else :
738738 assert False , "Exception not raised"
739+
740+
741+ @mark .asyncio
742+ async def test_cookie_samesite_with_ec2_public_url ():
743+ start_st ()
744+ init (
745+ supertokens_config = SupertokensConfig ("http://localhost:3567" ),
746+ app_info = InputAppInfo (
747+ app_name = "SuperTokens Demo" ,
748+ api_domain = "https://ec2-xx-yyy-zzz-0.compute-1.amazonaws.com:3001" ,
749+ website_domain = "https://blog.supertokens.com" ,
750+ api_base_path = "/" ,
751+ ),
752+ framework = "fastapi" ,
753+ recipe_list = [
754+ session .init (get_token_transfer_method = lambda _ , __ , ___ : "cookie" )
755+ ],
756+ )
757+
758+ # domain name isn't provided so browser decides to use the same host
759+ # which will be ec2-xx-yyy-zzz-0.compute-1.amazonaws.com
760+ assert SessionRecipe .get_instance ().config .cookie_domain is None
761+ assert SessionRecipe .get_instance ().config .cookie_same_site == "none"
762+ assert SessionRecipe .get_instance ().config .cookie_secure is True
763+
764+ reset ()
765+
766+ init (
767+ supertokens_config = SupertokensConfig ("http://localhost:3567" ),
768+ app_info = InputAppInfo (
769+ app_name = "SuperTokens Demo" ,
770+ api_domain = "http://ec2-xx-yyy-zzz-0.compute-1.amazonaws.com:3001" ,
771+ website_domain = "http://ec2-aa-bbb-ccc-0.compute-1.amazonaws.com:3000" ,
772+ api_base_path = "/" ,
773+ ),
774+ framework = "fastapi" ,
775+ recipe_list = [
776+ session .init (get_token_transfer_method = lambda _ , __ , ___ : "cookie" )
777+ ],
778+ )
779+
780+ assert SessionRecipe .get_instance ().config .cookie_domain is None
781+ assert SessionRecipe .get_instance ().config .cookie_same_site == "none"
782+ assert SessionRecipe .get_instance ().config .cookie_secure is False
783+
784+ reset ()
785+
786+ init (
787+ supertokens_config = SupertokensConfig ("http://localhost:3567" ),
788+ app_info = InputAppInfo (
789+ app_name = "SuperTokens Demo" ,
790+ api_domain = "http://ec2-xx-yyy-zzz-0.compute-1.amazonaws.com:3001" ,
791+ website_domain = "http://ec2-xx-yyy-zzz-0.compute-1.amazonaws.com:3000" ,
792+ api_base_path = "/" ,
793+ ),
794+ framework = "fastapi" ,
795+ recipe_list = [
796+ session .init (get_token_transfer_method = lambda _ , __ , ___ : "cookie" )
797+ ],
798+ )
799+
800+ assert SessionRecipe .get_instance ().config .cookie_domain is None
801+ assert SessionRecipe .get_instance ().config .cookie_same_site == "lax"
802+ assert SessionRecipe .get_instance ().config .cookie_secure is False
0 commit comments