GithubHelp home page GithubHelp logo

spring-security-sample's Introduction

Demonstration of Spring Security/Spring Cloud Gateway resetting Cookies on response

The application here consists of 4 parts:

  • Discovery Server
  • Spring Cloud Gateway API Gateway
  • Spring Authorization Server
  • Purchases API Resource Server

When subsequent requests are made through the API Gateway with an established session, the SESSION Cookie is getting reset in the response headers like Set-Cookie: Session=.

Prerequisites:

  1. Add an entry for auth-server to `/etc/hosts
127.0.0.1       localhost auth-server

Steps to start:

  1. Start the Discovery Server
  2. Start the Auth Server
  3. Start the API Gateway
  4. Start the Purchases API

Steps to reproduce

Open a browser and navigate to Purchases API

At this point you should be redirected to the Auth Server at http://auth-server:8080/login

Sign-in with the following credentials:

  • username: client1
  • password: password

Upon successful login you'll be redirected back to http://localhost:8765/purchases and the response should contain an empty array [ ]

Open the Chrome Inspector Network Tab and refresh the page. Now inspect the Response Headers and note there is a Set-Cookie attribute that looks like:

SESSION=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly; SameSite=Lax

This resets the session so subsequent calls trigger new sessions to be created.

Possible Workarounds

There are 2 possible workarounds to note.

Spring Cloud Gateway You can set a filter that removed the Set-Cookie response header

- RemoveResponseHeader=Set-Cookie

Spring Security You can set the Spring Security RequestCache to a NoOp implementation

http
    .requestCache( requestCache ->
            requestCache.requestCache( NoOpServerRequestCache.getInstance() )
    )

Either of these 2 solutions resolves the issue.

spring-security-sample's People

Contributors

dmfrey avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.