@@ -52,17 +52,24 @@ public function protect(
52
52
string $ tokenSharing = self ::ONE_TOKEN_PER_PAGE
53
53
):string {
54
54
$ forms = $ this ->document ->forms ;
55
+ $ tokenArray = [];
55
56
56
- if ($ forms ->length > 0 ) {
57
- $ token = $ this ->tokenStore ->generateNewToken ();
58
- $ this ->tokenStore ->saveToken ($ token );
57
+ $ token = null ;
59
58
59
+ if ($ forms ->length > 0 ) {
60
60
foreach ($ forms as $ form ) {
61
61
$ formMethod = $ form ->getAttribute ("method " );
62
62
if (strtolower ($ formMethod ) !== "post " ) {
63
63
continue ;
64
64
}
65
65
66
+ if ($ tokenSharing === self ::ONE_TOKEN_PER_FORM
67
+ || is_null ($ token )) {
68
+ $ token = $ this ->tokenStore ->generateNewToken ();
69
+ $ this ->tokenStore ->saveToken ($ token );
70
+ array_push ($ tokenArray , $ token );
71
+ }
72
+
66
73
$ csrfElement = $ this ->document ->createElement (
67
74
"input "
68
75
);
@@ -82,16 +89,13 @@ public function protect(
82
89
$ csrfElement ,
83
90
$ form ->firstChild
84
91
);
85
-
86
- if ($ tokenSharing === self ::ONE_TOKEN_PER_FORM ) {
87
- $ token = $ this ->tokenStore ->generateNewToken ();
88
- $ this ->tokenStore ->saveToken ($ token );
89
- }
90
92
}
91
93
}
92
- else {
94
+
95
+ if (is_null ($ token )) {
93
96
$ token = $ this ->tokenStore ->generateNewToken ();
94
97
$ this ->tokenStore ->saveToken ($ token );
98
+ array_push ($ tokenArray , $ token );
95
99
}
96
100
97
101
$ meta = $ this ->document ->querySelector (
@@ -123,8 +127,7 @@ public function protect(
123
127
$ head ->appendChild ($ meta );
124
128
}
125
129
126
- $ meta ->setAttribute ("content " , $ token );
127
-
130
+ $ meta ->setAttribute ("content " , implode (", " , $ tokenArray ));
128
131
return $ token ;
129
132
}
130
133
0 commit comments