Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 2604a45

Browse files
authored
Merge pull request #83 from firehooper/feature/82-same-site-cookies-config-deps-update
82 SameSite cookies config; deps update
2 parents 993b391 + 6b161c9 commit 2604a45

File tree

7 files changed

+41
-31
lines changed

7 files changed

+41
-31
lines changed

build.sbt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
lazy val commonSettings = commonSmlBuildSettings ++ ossPublishSettings ++ Seq(
22
organization := "com.softwaremill.akka-http-session",
3-
scalaVersion := "2.12.12",
4-
crossScalaVersions := Seq(scalaVersion.value, "2.13.4")
3+
scalaVersion := "2.13.8",
4+
crossScalaVersions := Seq(scalaVersion.value, "2.12.15")
55
)
66

7-
val akkaHttpVersion = "10.2.1"
8-
val akkaStreamsVersion = "2.6.10"
9-
val json4sVersion = "3.6.10"
7+
val akkaHttpVersion = "10.2.7"
8+
val akkaStreamsVersion = "2.6.18"
9+
val json4sVersion = "4.0.4"
1010
val akkaStreamsProvided = "com.typesafe.akka" %% "akka-stream" % akkaStreamsVersion % "provided"
1111
val akkaStreamsTestkit = "com.typesafe.akka" %% "akka-stream-testkit" % akkaStreamsVersion % "test"
1212

13-
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.3" % "test"
13+
val scalaTest = "org.scalatest" %% "scalatest" % "3.2.11" % "test"
1414

1515
lazy val rootProject = (project in file("."))
1616
.settings(commonSettings: _*)
@@ -26,7 +26,7 @@ lazy val core: Project = (project in file("core"))
2626
akkaStreamsProvided,
2727
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % "test",
2828
akkaStreamsTestkit,
29-
"org.scalacheck" %% "scalacheck" % "1.15.1" % "test",
29+
"org.scalacheck" %% "scalacheck" % "1.15.4" % "test",
3030
scalaTest
3131
)
3232
)
@@ -37,11 +37,13 @@ lazy val jwt: Project = (project in file("jwt"))
3737
name := "jwt",
3838
libraryDependencies ++= Seq(
3939
"org.json4s" %% "json4s-jackson" % json4sVersion,
40+
"org.json4s" %% "json4s-ast" % json4sVersion,
41+
"org.json4s" %% "json4s-core" % json4sVersion,
4042
akkaStreamsProvided,
4143
scalaTest
4244
),
4345
// generating docs for 2.13 causes an error: "not found: type DefaultFormats$"
44-
sources in (Compile, doc) := Seq.empty
46+
Compile / doc / sources := Seq.empty
4547
) dependsOn (core)
4648

4749
lazy val example: Project = (project in file("example"))
@@ -50,8 +52,8 @@ lazy val example: Project = (project in file("example"))
5052
publishArtifact := false,
5153
libraryDependencies ++= Seq(
5254
akkaStreamsProvided,
53-
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
54-
"ch.qos.logback" % "logback-classic" % "1.2.3",
55+
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",
56+
"ch.qos.logback" % "logback-classic" % "1.2.10",
5557
"org.json4s" %% "json4s-ext" % json4sVersion
5658
)
5759
)
@@ -61,16 +63,16 @@ lazy val javaTests: Project = (project in file("javaTests"))
6163
.settings(commonSettings: _*)
6264
.settings(
6365
name := "javaTests",
64-
testOptions in Test := Seq(Tests.Argument(TestFrameworks.JUnit, "-a")), // required for javadsl JUnit tests
66+
Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit, "-a")), // required for javadsl JUnit tests
6567
crossPaths := false, // https://github.com/sbt/junit-interface/issues/35
6668
publishArtifact := false,
6769
libraryDependencies ++= Seq(
6870
akkaStreamsProvided,
6971
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
7072
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % "test",
7173
akkaStreamsTestkit,
72-
"junit" % "junit" % "4.13.1" % "test",
73-
"com.novocode" % "junit-interface" % "0.11" % "test",
74+
"junit" % "junit" % "4.13.2" % "test",
75+
"com.github.sbt" % "junit-interface" % "0.13.3" % "test",
7476
scalaTest
7577
)
7678
)

core/src/main/resources/reference.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ akka.http.session {
55
path = /
66
secure = false
77
http-only = true
8+
same-site = Lax
89
}
910
header {
1011
send-to-client-name = "Set-Authorization"
@@ -26,6 +27,7 @@ akka.http.session {
2627
path = /
2728
secure = false
2829
http-only = false
30+
same-site = Lax
2931
}
3032
submitted-name = "X-XSRF-TOKEN"
3133
}
@@ -37,6 +39,7 @@ akka.http.session {
3739
path = /
3840
secure = false
3941
http-only = true
42+
same-site = Lax
4043
}
4144
header {
4245
send-to-client-name = "Set-Refresh-Token"

core/src/main/scala/com/softwaremill/session/SessionConfig.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import java.util.concurrent.TimeUnit
55
import com.softwaremill.session.JwsAlgorithm.{HmacSHA256, Rsa}
66
import com.softwaremill.session.SessionConfig.{JwsConfig, JwtConfig}
77
import com.typesafe.config.{Config, ConfigFactory, ConfigValueFactory}
8+
import akka.http.scaladsl.model.headers.SameSite
89

9-
case class CookieConfig(name: String, domain: Option[String], path: Option[String], secure: Boolean, httpOnly: Boolean)
10+
case class CookieConfig(name: String, domain: Option[String], path: Option[String], secure: Boolean, httpOnly: Boolean, sameSite: Option[SameSite])
1011

1112
case class HeaderConfig(sendToClientHeaderName: String, getFromClientHeaderName: String)
1213

@@ -119,7 +120,8 @@ object SessionConfig {
119120
domain = scopedConfig.getOptionalString("cookie.domain"),
120121
path = scopedConfig.getOptionalString("cookie.path"),
121122
secure = scopedConfig.getBoolean("cookie.secure"),
122-
httpOnly = scopedConfig.getBoolean("cookie.http-only")
123+
httpOnly = scopedConfig.getBoolean("cookie.http-only"),
124+
sameSite = scopedConfig.getOptionalString("cookie.same-site").flatMap { SameSite(_) },
123125
),
124126
sessionHeaderConfig = HeaderConfig(
125127
sendToClientHeaderName = scopedConfig.getString("header.send-to-client-name"),
@@ -132,15 +134,17 @@ object SessionConfig {
132134
domain = csrfConfig.getOptionalString("cookie.domain"),
133135
path = csrfConfig.getOptionalString("cookie.path"),
134136
secure = csrfConfig.getBoolean("cookie.secure"),
135-
httpOnly = csrfConfig.getBoolean("cookie.http-only")
137+
httpOnly = csrfConfig.getBoolean("cookie.http-only"),
138+
sameSite = scopedConfig.getOptionalString("cookie.same-site").flatMap { SameSite(_) },
136139
),
137140
csrfSubmittedName = csrfConfig.getString("submitted-name"),
138141
refreshTokenCookieConfig = CookieConfig(
139142
name = refreshTokenConfig.getString("cookie.name"),
140143
domain = refreshTokenConfig.getOptionalString("cookie.domain"),
141144
path = refreshTokenConfig.getOptionalString("cookie.path"),
142145
secure = refreshTokenConfig.getBoolean("cookie.secure"),
143-
httpOnly = refreshTokenConfig.getBoolean("cookie.http-only")
146+
httpOnly = refreshTokenConfig.getBoolean("cookie.http-only"),
147+
sameSite = scopedConfig.getOptionalString("cookie.same-site").flatMap { SameSite(_) },
144148
),
145149
refreshTokenHeaderConfig = HeaderConfig(
146150
sendToClientHeaderName = refreshTokenConfig.getString("header.send-to-client-name"),

core/src/main/scala/com/softwaremill/session/SessionManager.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ trait ClientSessionManager[T] {
5050
domain = config.sessionCookieConfig.domain,
5151
path = config.sessionCookieConfig.path,
5252
secure = config.sessionCookieConfig.secure,
53-
httpOnly = config.sessionCookieConfig.httpOnly
54-
)
53+
httpOnly = config.sessionCookieConfig.httpOnly,
54+
).withSameSite(config.sessionCookieConfig.sameSite)
5555

5656
def createHeader(data: T) = createHeaderWithValue(encode(data))
5757

@@ -114,8 +114,8 @@ trait CsrfManager[T] {
114114
domain = config.csrfCookieConfig.domain,
115115
path = config.csrfCookieConfig.path,
116116
secure = config.csrfCookieConfig.secure,
117-
httpOnly = config.csrfCookieConfig.httpOnly
118-
)
117+
httpOnly = config.csrfCookieConfig.httpOnly,
118+
).withSameSite(config.csrfCookieConfig.sameSite)
119119
}
120120

121121
trait RefreshTokenManager[T] {
@@ -168,8 +168,8 @@ trait RefreshTokenManager[T] {
168168
domain = config.refreshTokenCookieConfig.domain,
169169
path = config.refreshTokenCookieConfig.path,
170170
secure = config.refreshTokenCookieConfig.secure,
171-
httpOnly = config.refreshTokenCookieConfig.httpOnly
172-
)
171+
httpOnly = config.refreshTokenCookieConfig.httpOnly,
172+
).withSameSite(config.refreshTokenCookieConfig.sameSite)
173173

174174
def createHeader(value: String) =
175175
RawHeader(name = config.refreshTokenHeaderConfig.sendToClientHeaderName, value = value)

jwt/src/main/java/com/softwaremill/session/javadsl/JwtSessionSerializers.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.softwaremill.session.JValueSessionSerializer$;
44
import com.softwaremill.session.SessionSerializer;
55
import org.json4s.DefaultFormats$;
6-
import org.json4s.JsonAST;
6+
import org.json4s.JValue;
77

88
/**
99
* Wrapper for session transports in com.softwaremill.session.JValueSessionSerializer
@@ -12,11 +12,11 @@ public final class JwtSessionSerializers {
1212

1313
public static final DefaultFormats$ DefaultUtcDateFormat = DefaultFormats$.MODULE$;
1414

15-
public static final SessionSerializer<String, JsonAST.JValue> StringToJValueSessionSerializer = JValueSessionSerializer$.MODULE$.stringToJValueSessionSerializer();
16-
public static final SessionSerializer<Integer, JsonAST.JValue> IntToJValueSessionSerializer = (SessionSerializer<Integer, JsonAST.JValue>) (SessionSerializer) JValueSessionSerializer$.MODULE$.intToJValueSessionSerializer();
17-
public static final SessionSerializer<Long, JsonAST.JValue> LongToJValueSessionSerializer = (SessionSerializer<Long, JsonAST.JValue>) (SessionSerializer) JValueSessionSerializer$.MODULE$.longToJValueSessionSerializer();
18-
public static final SessionSerializer<Float, JsonAST.JValue> FloatToJValueSessionSerializer = (SessionSerializer<Float, JsonAST.JValue>) (SessionSerializer) JValueSessionSerializer$.MODULE$.floatToJValueSessionSerializer();
19-
public static final SessionSerializer<Double, JsonAST.JValue> DoubleToJValueSessionSerializer = (SessionSerializer<Double, JsonAST.JValue>) (SessionSerializer) JValueSessionSerializer$.MODULE$.doubleToJValueSessionSerializer();
15+
public static final SessionSerializer<String, JValue> StringToJValueSessionSerializer = JValueSessionSerializer$.MODULE$.stringToJValueSessionSerializer();
16+
public static final SessionSerializer<Integer, JValue> IntToJValueSessionSerializer = (SessionSerializer<Integer, JValue>) (SessionSerializer) JValueSessionSerializer$.MODULE$.intToJValueSessionSerializer();
17+
public static final SessionSerializer<Long, JValue> LongToJValueSessionSerializer = (SessionSerializer<Long, JValue>) (SessionSerializer) JValueSessionSerializer$.MODULE$.longToJValueSessionSerializer();
18+
public static final SessionSerializer<Float, JValue> FloatToJValueSessionSerializer = (SessionSerializer<Float, JValue>) (SessionSerializer) JValueSessionSerializer$.MODULE$.floatToJValueSessionSerializer();
19+
public static final SessionSerializer<Double, JValue> DoubleToJValueSessionSerializer = (SessionSerializer<Double, JValue>) (SessionSerializer) JValueSessionSerializer$.MODULE$.doubleToJValueSessionSerializer();
2020

2121
private JwtSessionSerializers() {
2222
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.4.3
1+
sbt.version=1.6.1

project/plugins.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-common" % "1.9.14")
22
addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-publish" % "1.9.14")
3-
addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-extra" % "1.9.14")
3+
addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-extra" % "1.9.14")
4+
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.16")

0 commit comments

Comments
 (0)