Browse Source

* Add support for SameSite attribute of cookie (bug ID 0037115)

git-svn-id: trunk@45446 -
michael 5 years ago
parent
commit
3c75ae82d2
2 changed files with 11 additions and 0 deletions
  1. 10 0
      packages/fcl-web/src/base/httpdefs.pp
  2. 1 0
      packages/fcl-web/src/base/httpprotocol.pp

+ 10 - 0
packages/fcl-web/src/base/httpdefs.pp

@@ -97,6 +97,7 @@ const
   SCookiePath     = httpProtocol.SCookiePath;
   SCookiePath     = httpProtocol.SCookiePath;
   SCookieSecure   = httpProtocol.SCookieSecure;
   SCookieSecure   = httpProtocol.SCookieSecure;
   SCookieHttpOnly = httpProtocol.SCookieHttpOnly;
   SCookieHttpOnly = httpProtocol.SCookieHttpOnly;
+  SCookieSameSite = httpProtocol.SCookieSameSite;
 
 
   HTTPMonths : array[1..12] of string[3] = (
   HTTPMonths : array[1..12] of string[3] = (
     'Jan', 'Feb', 'Mar', 'Apr',
     'Jan', 'Feb', 'Mar', 'Apr',
@@ -148,11 +149,13 @@ type
   TRequest = Class;
   TRequest = Class;
 
 
   { TCookie }
   { TCookie }
+  TSameSite = (ssEmpty,ssNone,ssStrict,ssLax);
 
 
   TCookie = class(TCollectionItem)
   TCookie = class(TCollectionItem)
   private
   private
     FHttpOnly: Boolean;
     FHttpOnly: Boolean;
     FName: string;
     FName: string;
+    FSameSite: TSameSite;
     FValue: string;
     FValue: string;
     FPath: string;
     FPath: string;
     FDomain: string;
     FDomain: string;
@@ -171,6 +174,7 @@ type
     property Expires: TDateTime read FExpires write FExpires;
     property Expires: TDateTime read FExpires write FExpires;
     property Secure: Boolean read FSecure write FSecure;
     property Secure: Boolean read FSecure write FSecure;
     property HttpOnly: Boolean read FHttpOnly write FHttpOnly;
     property HttpOnly: Boolean read FHttpOnly write FHttpOnly;
+    property SameSite: TSameSite Read FSameSite Write FSameSite;
     Property AsString : String Read GetAsString;
     Property AsString : String Read GetAsString;
   end;
   end;
 
 
@@ -2317,6 +2321,10 @@ function TCookie.GetAsString: string;
     Result:=Result+';'+S;
     Result:=Result+';'+S;
   end;
   end;
 
 
+Const
+  SSameSiteValues : Array[TSameSite] of string
+                  = ('','None','Strict','Lax');
+
 Var
 Var
   Y,M,D : Word;
   Y,M,D : Word;
 
 
@@ -2338,6 +2346,8 @@ begin
       AddToResult(SCookieHttpOnly);
       AddToResult(SCookieHttpOnly);
     if FSecure then
     if FSecure then
       AddToResult(SCookieSecure);
       AddToResult(SCookieSecure);
+    if FSameSite<>ssEmpty then
+      AddToResult(SSameSiteValues[FSameSite]);
   except
   except
 {$ifdef cgidebug}
 {$ifdef cgidebug}
     On E : Exception do
     On E : Exception do

+ 1 - 0
packages/fcl-web/src/base/httpprotocol.pp

@@ -87,6 +87,7 @@ Const
   SCookiePath     = ' Path=%s';
   SCookiePath     = ' Path=%s';
   SCookieSecure   = ' Secure';
   SCookieSecure   = ' Secure';
   SCookieHttpOnly = ' HttpOnly';
   SCookieHttpOnly = ' HttpOnly';
+  SCookieSameSite = ' SameSite';
 
 
   HTTPMonths: array[1..12] of string[3] = (
   HTTPMonths: array[1..12] of string[3] = (
     'Jan', 'Feb', 'Mar', 'Apr',
     'Jan', 'Feb', 'Mar', 'Apr',