Skip to content

Commit

Permalink
add secure and httpOnly to cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
cwansart committed Aug 24, 2024
1 parent 5dd0930 commit 7619384
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
//runtimeOnly 'com.h2database:h2'
developmentOnly 'com.h2database:h2'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ public String save(@RequestParam(name = "id", required = true) long id,
vote.setUserId(userId);
voteRepo.save(vote);

response.addCookie(new Cookie("unipoll-user-id", userId));
Cookie cookie = new Cookie("unipoll-user-id", userId);
cookie.setHttpOnly(true);
cookie.setSecure(true);
response.addCookie(cookie);

return "redirect:/vote?id=" + id;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
spring.application.name=unipoll
server.servlet.session.cookie.secure=true

# default http port
#server.port=80
Expand Down

0 comments on commit 7619384

Please sign in to comment.