Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit fdedfb9

Browse files
authored
SameSite attribute for cookies change (#27)
* update * mvn build success * samesite attribute added * .gitignore fix * samesite test cases * path changes * for passing ci builds * updated for travis ci build tests commented oraclejdk9 added support for Java 12,13,14 * added openjdk9 * typo and readme update
1 parent d8c9c6e commit fdedfb9

File tree

12 files changed

+112
-33
lines changed

12 files changed

+112
-33
lines changed

.classpath

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<attributes>
1111
<attribute name="optional" value="true"/>
1212
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
1314
</attributes>
1415
</classpathentry>
1516
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
@@ -20,12 +21,30 @@
2021
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
2122
<attributes>
2223
<attribute name="maven.pomderived" value="true"/>
24+
<attribute name="test" value="true"/>
2325
</attributes>
2426
</classpathentry>
25-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
27+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
2628
<attributes>
2729
<attribute name="maven.pomderived" value="true"/>
2830
</attributes>
2931
</classpathentry>
32+
<classpathentry kind="src" path="target/generated-sources/annotations">
33+
<attributes>
34+
<attribute name="optional" value="true"/>
35+
<attribute name="maven.pomderived" value="true"/>
36+
<attribute name="ignore_optional_problems" value="true"/>
37+
<attribute name="m2e-apt" value="true"/>
38+
</attributes>
39+
</classpathentry>
40+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
41+
<attributes>
42+
<attribute name="optional" value="true"/>
43+
<attribute name="maven.pomderived" value="true"/>
44+
<attribute name="ignore_optional_problems" value="true"/>
45+
<attribute name="m2e-apt" value="true"/>
46+
<attribute name="test" value="true"/>
47+
</attributes>
48+
</classpathentry>
3049
<classpathentry kind="output" path="target/classes"/>
3150
</classpath>

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/release.properties
66
/pom.xml.releaseBackup
77
*.iml
8-
.idea
8+
.idea
9+
.vscode
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.apt.aptEnabled=false
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4-
org.eclipse.jdt.core.compiler.compliance=1.7
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
55
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
67
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
78
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8-
org.eclipse.jdt.core.compiler.source=1.7
9+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
10+
org.eclipse.jdt.core.compiler.processAnnotations=disabled
11+
org.eclipse.jdt.core.compiler.release=disabled
12+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<faceted-project>
3-
<installed facet="java" version="1.7"/>
3+
<installed facet="java" version="1.8"/>
44
<installed facet="jboss.m2" version="1.0"/>
55
</faceted-project>

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
language: java
22

33
jdk:
4-
- oraclejdk8
5-
- oraclejdk9
4+
# - oraclejdk8
5+
# - oraclejdk9
66
- oraclejdk11
7+
- oraclejdk12
8+
- oraclejdk13
9+
- oraclejdk14
710
- openjdk8
11+
- openjdk9
812
- openjdk10
9-
- openjdk11
13+
- openjdk11
14+
- openjdk12
15+
- openjdk13
16+
- openjdk14

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ cookies.get( "name" ); // => "value"
236236
cookies.remove( "name", httpOnlyCookie );
237237
```
238238

239+
### sameSite
240+
241+
Define whether your cookie should be restricted to a first party or same-site context
242+
243+
**Default:** not set
244+
245+
Note that more recent browsers are making "Lax" the default value even without specifiying anything here.
246+
247+
**Examples:**
248+
249+
```java
250+
Cookies cookies = Cookies.initFromServlet( request, response );
251+
cookies.set( "name", "value", Attributes.empty().sameSite( "Lax" ) );
252+
cookies.get( "name" ); // => "value"
253+
```
254+
239255
## Converter
240256

241257
Create a new instance of the api that overrides the default decoding implementation.

pom.xml

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
<properties>
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1212
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13-
<selenium.version>3.141.59</selenium.version>
14-
<wildfly.version>15.0.1.Final</wildfly.version>
13+
<selenium.version>2.45.0</selenium.version>
14+
<wildfly.version>20.0.1.Final</wildfly.version>
1515
<project.scm.id>java-cookie-scm</project.scm.id>
16+
<java.version>1.8</java.version>
1617
</properties>
1718
<licenses>
1819
<license>
@@ -45,16 +46,16 @@
4546
<plugins>
4647
<plugin>
4748
<artifactId>maven-compiler-plugin</artifactId>
48-
<version>3.1</version>
49+
<version>3.8.1</version>
4950
<configuration>
50-
<source>1.6</source>
51-
<target>1.6</target>
51+
<source>${java.version}</source>
52+
<target>${java.version}</target>
5253
</configuration>
5354
</plugin>
5455
<plugin>
5556
<groupId>org.apache.maven.plugins</groupId>
5657
<artifactId>maven-release-plugin</artifactId>
57-
<version>2.5.2</version>
58+
<version>3.0.0-M1</version>
5859
<configuration>
5960
<useReleaseProfile>false</useReleaseProfile>
6061
<releaseProfiles>release</releaseProfiles>
@@ -69,8 +70,8 @@
6970
<dependency>
7071
<groupId>org.jboss.arquillian</groupId>
7172
<artifactId>arquillian-bom</artifactId>
72-
<version>1.4.1.Final</version>
73-
<scope>import</scope>
73+
<version>1.6.0.Final</version>
74+
<scope>test</scope>
7475
<type>pom</type>
7576
</dependency>
7677
</dependencies>
@@ -85,12 +86,12 @@
8586
<dependency>
8687
<groupId>joda-time</groupId>
8788
<artifactId>joda-time</artifactId>
88-
<version>2.10.1</version>
89+
<version>2.10.6</version>
8990
</dependency>
9091
<dependency>
9192
<groupId>com.fasterxml.jackson.core</groupId>
9293
<artifactId>jackson-databind</artifactId>
93-
<version>2.9.8</version>
94+
<version>2.11.2</version>
9495
</dependency>
9596
<dependency>
9697
<groupId>junit</groupId>
@@ -119,43 +120,43 @@
119120
<dependency>
120121
<groupId>org.jboss.arquillian.protocol</groupId>
121122
<artifactId>arquillian-protocol-servlet</artifactId>
122-
<version>1.4.1.Final</version>
123+
<version>1.6.0.Final</version>
123124
<scope>test</scope>
124125
</dependency>
125126
<dependency>
126127
<groupId>org.jboss.arquillian.junit</groupId>
127128
<artifactId>arquillian-junit-container</artifactId>
128-
<version>1.4.1.Final</version>
129+
<version>1.6.0.Final</version>
129130
<scope>test</scope>
130131
</dependency>
131132
<dependency>
132133
<groupId>org.wildfly.arquillian</groupId>
133134
<artifactId>wildfly-arquillian-container-managed</artifactId>
134-
<version>2.1.1.Final</version>
135+
<version>2.2.0.Final</version>
135136
<scope>test</scope>
136137
</dependency>
137138
<dependency>
138139
<groupId>org.jboss.shrinkwrap.resolver</groupId>
139140
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
140-
<version>3.1.3</version>
141+
<version>3.1.4</version>
141142
<scope>test</scope>
142143
</dependency>
143144
<dependency>
144145
<groupId>org.jboss.shrinkwrap.resolver</groupId>
145146
<artifactId>shrinkwrap-resolver-spi</artifactId>
146-
<version>3.1.3</version>
147+
<version>3.1.4</version>
147148
<scope>test</scope>
148149
</dependency>
149150
<dependency>
150151
<groupId>org.apache.httpcomponents</groupId>
151152
<artifactId>httpclient</artifactId>
152-
<version>4.5.7</version>
153+
<version>4.5.12</version>
153154
<scope>test</scope>
154155
</dependency>
155156
<dependency>
156157
<groupId>org.apache.httpcomponents</groupId>
157158
<artifactId>fluent-hc</artifactId>
158-
<version>4.5.7</version>
159+
<version>4.5.12</version>
159160
<scope>test</scope>
160161
</dependency>
161162
</dependencies>
@@ -192,9 +193,9 @@
192193
</executions>
193194
</plugin>
194195
<plugin>
195-
<groupId>org.codehaus.mojo</groupId>
196-
<artifactId>failsafe-maven-plugin</artifactId>
197-
<version>2.4.3-alpha-1</version>
196+
<groupId>org.apache.maven.plugins</groupId>
197+
<artifactId>maven-failsafe-plugin</artifactId>
198+
<version>2.22.2</version>
198199
<executions>
199200
<execution>
200201
<goals>
@@ -207,7 +208,7 @@
207208
<plugin>
208209
<groupId>com.github.eirslett</groupId>
209210
<artifactId>frontend-maven-plugin</artifactId>
210-
<version>1.5</version>
211+
<version>1.10.0</version>
211212
<executions>
212213
<execution>
213214
<id>install node and npm</id>
@@ -262,7 +263,7 @@
262263
<plugin>
263264
<groupId>org.apache.maven.plugins</groupId>
264265
<artifactId>maven-javadoc-plugin</artifactId>
265-
<version>3.0.1</version>
266+
<version>3.2.0</version>
266267
<executions>
267268
<execution>
268269
<id>attach-javadocs</id>
@@ -275,7 +276,7 @@
275276
<plugin>
276277
<groupId>org.apache.maven.plugins</groupId>
277278
<artifactId>maven-source-plugin</artifactId>
278-
<version>3.0.1</version>
279+
<version>3.2.1</version>
279280
<executions>
280281
<execution>
281282
<id>attach-sources</id>

src/main/java/com/github/jscookie/javacookie/AttributesDefinition.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public abstract class AttributesDefinition {
1111
abstract Boolean secure();
1212
public abstract AttributesDefinition httpOnly( Boolean httpOnly );
1313
abstract Boolean httpOnly();
14+
public abstract AttributesDefinition sameSite( String sameSite );
15+
abstract String sameSite();
1416
}

src/main/java/com/github/jscookie/javacookie/Cookies.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ public synchronized void set( String name, String value, AttributesDefinition at
147147
header.append( "; HttpOnly" );
148148
}
149149

150+
String sameSite = attributes.sameSite();
151+
if ( sameSite != null ) {
152+
header.append( "; SameSite=" + sameSite );
153+
}
154+
150155
if ( response.isCommitted() ) {
151156
return;
152157
}
@@ -416,6 +421,7 @@ public static class Attributes extends AttributesDefinition {
416421
private String domain;
417422
private Boolean secure;
418423
private Boolean httpOnly;
424+
private String sameSite;
419425

420426
private Attributes() {}
421427

@@ -473,6 +479,16 @@ public Attributes httpOnly( Boolean httpOnly ) {
473479
return this;
474480
}
475481

482+
@Override
483+
String sameSite() {
484+
return sameSite;
485+
}
486+
@Override
487+
public Attributes sameSite( String sameSite ) {
488+
this.sameSite = sameSite;
489+
return this;
490+
}
491+
476492
private Attributes merge( AttributesDefinition reference ) {
477493
if ( reference.path() != null ) {
478494
path = reference.path();
@@ -489,6 +505,9 @@ private Attributes merge( AttributesDefinition reference ) {
489505
if ( reference.httpOnly() != null ) {
490506
httpOnly = reference.httpOnly();
491507
}
508+
if ( reference.sameSite() != null ) {
509+
sameSite = reference.sameSite();
510+
}
492511
return this;
493512
}
494513
}

0 commit comments

Comments
 (0)