@@ -243,19 +243,33 @@ void http_assemble_response (Webserver_Request& webserver_request)
243243 // The Secure attribute is set.
244244 // It is meant to keep cookie communication limited to encrypted transmission,
245245 // directing browsers to use cookies only via secure/encrypted connections.
246- // For maximum security, cookies with the Secure attribute should only be set over a secure connection.
246+ // Cookies with the Secure attribute should only be set over a secure connection.
247+ // If the Secure attribute is set and the connection is over http,
248+ // then the browser indicates:
249+ // This attempt to set a cookie via a Set-Cookie header was blocked
250+ // because it had the "Secure" attribute but was not received over a secure connection.
251+ // The result of this is that a user cannot login to Bibledit Cloud over a plain connection.
252+ // The localhost binding works because most browsers have special-case code
253+ // to treat connections to that host name as "secure", even if they don't use HTTPS.
247254
248255 // The HttpOnly attribute means that the cookie can be accessed by the HTTP API only,
249256 // and not by for example Javascript running in the browser.
250257 // This provides extra security.
251258
252259 // The setting "SameSite" is set to "None" to enable cookies while embedded in e.g. NextCloud,
253260 // which works via an iframe on a different origin.
261+ // If set to "None", this only works on a secure connection.
262+ // On a plain connection, the browser says:
263+ // This attempt to set a cookie via a Set-Cookie header was blocked
264+ // because it had the "SameSite=None" attribute but did not have the "Secure" attribute,
265+ // which is required in order to use "SameSite=None".
254266
255267 std::string identifier = webserver_request.session_identifier ;
256268 if (identifier.empty ())
257269 identifier = filter::strings::get_new_random_string ();
258- const std::string cookie = " Session=" + identifier + " ; Path=/; Max-Age=2678400; HttpOnly; SameSite=None; Secure" ;
270+ std::string cookie = " Session=" + identifier + " ; Path=/; Max-Age=2678400; HttpOnly" ;
271+ if (webserver_request.secure )
272+ cookie.append (" ; SameSite=None; Secure" );
259273 response.push_back (" Set-Cookie: " + cookie);
260274 }
261275 if (!webserver_request.header .empty ())
0 commit comments