Skip to content

Commit 7619384

Browse files
committed
add secure and httpOnly to cookie
1 parent 5dd0930 commit 7619384

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies {
2323
implementation 'org.springframework.boot:spring-boot-starter-web'
2424
implementation 'org.springframework.boot:spring-boot-starter-security'
2525
developmentOnly 'org.springframework.boot:spring-boot-devtools'
26-
//runtimeOnly 'com.h2database:h2'
26+
developmentOnly 'com.h2database:h2'
2727
runtimeOnly 'org.postgresql:postgresql'
2828
testImplementation 'org.springframework.boot:spring-boot-starter-test'
2929
//testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

src/main/java/de/cwansart/unipoll/controller/VoteController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ public String save(@RequestParam(name = "id", required = true) long id,
9595
vote.setUserId(userId);
9696
voteRepo.save(vote);
9797

98-
response.addCookie(new Cookie("unipoll-user-id", userId));
98+
Cookie cookie = new Cookie("unipoll-user-id", userId);
99+
cookie.setHttpOnly(true);
100+
cookie.setSecure(true);
101+
response.addCookie(cookie);
99102

100103
return "redirect:/vote?id=" + id;
101104
}

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
spring.application.name=unipoll
2+
server.servlet.session.cookie.secure=true
23

34
# default http port
45
#server.port=80

0 commit comments

Comments
 (0)