<commit_before>package lila.common

import lila.common.config.NetDomain
import ornicar.scalalib.Random
import play.api.mvc._

final class LilaCookie(domain: NetDomain, baker: SessionCookieBaker) {

  private val cookieDomain = domain.value.split(":").head

  def makeSessionId(implicit req: RequestHeader) = session(LilaCookie.sessionId, Random secureString 22)

  def session(name: String, value: String)(implicit req: RequestHeader): Cookie =
    withSession { s =>
      s + (name -> value)
    }

  def newSession(implicit req: RequestHeader): Cookie = withSession(_ => Session.emptyCookie)

  def withSession(op: Session => Session)(implicit req: RequestHeader): Cookie =
    cookie(
      baker.COOKIE_NAME,
      baker.encode(baker.serialize(op(req.session)))
    )

  def cookie(name: String, value: String, maxAge: Option[Int] = None, httpOnly: Option[Boolean] = None)(
      implicit req: RequestHeader
  ): Cookie =
    Cookie(
      name,
      value,
      maxAge orElse baker.maxAge orElse 86400.some,
      "/",
      cookieDomain.some,
      baker.secure || req.headers.get("X-Forwarded-Proto").contains("https"),
      httpOnly | baker.httpOnly,
      baker.sameSite
    )

  def discard(name: String) =
    DiscardingCookie(name, "/", cookieDomain.some, baker.httpOnly)

  def ensure(req: RequestHeader)(res: Result): Result =
    if (req.session.data.contains(LilaCookie.sessionId)) res
    else res withCookies makeSessionId(req)
}

object LilaCookie {

  val sessionId = "sid"
}<commit_msg>Revert "explicitly set SameSite=lax for cookies"<commit_after>package lila.common

import lila.common.config.NetDomain
import ornicar.scalalib.Random
import play.api.mvc._

final class LilaCookie(domain: NetDomain, baker: SessionCookieBaker) {

  private val cookieDomain = domain.value.split(":").head

  def makeSessionId(implicit req: RequestHeader) = session(LilaCookie.sessionId, Random secureString 22)

  def session(name: String, value: String)(implicit req: RequestHeader): Cookie =
    withSession { s =>
      s + (name -> value)
    }

  def newSession(implicit req: RequestHeader): Cookie = withSession(_ => Session.emptyCookie)

  def withSession(op: Session => Session)(implicit req: RequestHeader): Cookie =
    cookie(
      baker.COOKIE_NAME,
      baker.encode(baker.serialize(op(req.session)))
    )

  def cookie(name: String, value: String, maxAge: Option[Int] = None, httpOnly: Option[Boolean] = None)(
      implicit req: RequestHeader
  ): Cookie =
    Cookie(
      name,
      value,
      maxAge orElse baker.maxAge orElse 86400.some,
      "/",
      cookieDomain.some,
      baker.secure || req.headers.get("X-Forwarded-Proto").contains("https"),
      httpOnly | baker.httpOnly
    )

  def discard(name: String) =
    DiscardingCookie(name, "/", cookieDomain.some, baker.httpOnly)

  def ensure(req: RequestHeader)(res: Result): Result =
    if (req.session.data.contains(LilaCookie.sessionId)) res
    else res withCookies makeSessionId(req)
}

object LilaCookie {

  val sessionId = "sid"
}
{'fraction_non_alphanumeric': 0.11828665568369028, 'fraction_numerical': 0.004612850082372323, 'mean_word_length': 3.8498402555910545, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2126099', 'n_tokens_mistral': 994, 'n_tokens_neox': 940, 'n_words': 220}