You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 2, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+10-10
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ Content-Length: 6
80
80
value1
81
81
```
82
82
83
-
[Here's an example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/data_types/CustomTypeSession) with a `CustomType` data type session:
83
+
[Here's an example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/data_types/CustomTypeSession.java) with a `CustomType` data type session:
The timestamp attached to the session is `1505470200180` and translates to `Fri Sep 15 2017 10:10:00` which is 5 minutes ahead of the time, when the request was sent `Fri, 15 Sep 2017 10:05:00 GMT`.
207
207
208
-
## Session Continuity #{refreshable}
208
+
## <aname="refreshable"> Session Continuity
209
209
### What type of sessions are available
210
210
There is the `OneOff` session which when expired is of no use anymore.
211
211
An alternative is the `Refreshable` session.
@@ -342,7 +342,8 @@ This can be either `OneOff` or `Refreshable`.
342
342
Yes.
343
343
344
344
### <aname="secure-cookie"></a>How can I use Cookies in a secure way?
345
-
1. Use the `invalidateSession` directive when a user logs out or doesn't need that session any longer.
345
+
1. Use the `invalidateSession` directive when a user logs out or doesn't need that session any longer
346
+
346
347
This is demonstrated by the `do_logout` route in the [CookieTransport example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/transport/CookieTransport.java).
347
348
Its purpose is to send an empty `_sessiondata` Cookie to the client (typically a browser).
348
349
In consequence, the browser should erase that Cookie to prevent an attacker to read the cookie later on.
@@ -362,6 +363,7 @@ The Cookie does no longer contain any session data.
362
363
It's still possible, that although the browser erased the Cookie, the attacker got it. Therefore:
363
364
364
365
2. Use a sensible `max-age` value which defaults to 7 days
366
+
365
367
For use cases where it make sense, set the `max-age` property to a low value, for example `5 minutes`.
366
368
This is especially true, when your application allows to access sensitive data, like bank accounts, emails, etc.
367
369
The `max-age` property is set in `application.conf`, like in [this example](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/resources/application.conf).
@@ -380,6 +382,7 @@ The supplied authentication is not authorized to access this resource
380
382
3. Secure your transfer protocol - use HTTPS.
381
383
382
384
4. Enable the `Secure` option for Cookies
385
+
383
386
The `Secure` attribute is explained in [RFC 6265](https://tools.ietf.org/html/rfc6265#section-4.1.2.5) in more detail.
384
387
This does not prevent the server from sending the Cookie to the client.
385
388
It's just a flag for the client.
@@ -456,7 +459,7 @@ In such a use-case however, [Refresh Tokens](#refreshable) which are valid for 1
456
459
457
460
### Is it possible to modify the session data on the client side?
458
461
No. The session is signed by the server and changes to the session's content are picked up and rejected.
459
-
In other words, it is not possible to login with valid credentials and then havong a valid token pretend to be a different user, like in this example:
462
+
In other words, it is not possible to login with valid credentials and then having a valid token pretend to be a different user, like in this example:
@@ -520,7 +523,7 @@ You may not want to share it for various reasons, like when it is a sequential n
520
523
Another example would be data that is expensive to fetch or require access to a paid API or a 3rd party call.
521
524
If such data has to be put in context with a particular user, therefore sent as part of the session data, and the client should not be able to read it, then encryption is the way to go.
522
525
523
-
## Session Directives #{directives}
526
+
## <aname="directives"></a> Session Directives
524
527
### What are these session directives exactly for?
525
528
Including `akka-http-session` directives into the route chain, you can require an endpoint to be accessible only, if a valid session is provided by the client.
526
529
Also there's a directive to initiate or invalidate a session when accessing a particular endpoint.
@@ -531,7 +534,7 @@ Adding this directive to a route chain allows you to initialize a session.
531
534
Depending on the transport type, either a `Set-Authorization` header or a `Set-Cookie` header are set with a new session.
532
535
It is up to the client to read the appropriate Header and use the session in subsequent calls.
533
536
534
-
### What is the `session` directive good for? #{session-directive}
537
+
### <aname="session-directive"></a> What is the `session` directive good for?
535
538
This directive is responsible for extracting the session result to be used further on the server side.
536
539
A session result can be `Decoded` (valid), `CreatedFromToken`, `Expired`, `Corrupt` or having no token present `TokenNotFound`
537
540
The directive does not require the client to provide a session.
@@ -585,7 +588,7 @@ Take a look at [How can I use Cookies in a secure way?](#secure-cookie) and [Eve
585
588
This one is very similar to the `session` directive.
586
589
In this case however, we get access to the session details, which is an `Optional`.
587
590
Based on that we can decide on the server side, how to proceed.
588
-
In the [OptionalSession](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/directives/OptionalSession.java) example, we either reply with `no session` or with the session details, if present.
591
+
In the [OptionalSession](https://github.com/softwaremill/akka-http-session-faq/tree/master/src/main/java/session/directives/OptionalSessionDirective.java) example, we either reply with `no session` or with the session details, if present.
589
592
590
593
### What is the `requiredSession` directive good for?
591
594
This directive is used to secure endpoints.
@@ -683,7 +686,6 @@ Content-Length: 8
683
686
684
687
my_login
685
688
```
686
-
**Do not forget to include the Bearer prefix, otherwise the server will display a WARN message.**
687
689
688
690
## CSRF protection
689
691
### What is it and (when) do I need it?
@@ -725,8 +727,6 @@ Welcome
725
727
```
726
728
Without that cookie we would be not able to access the `/api/do_login` endpoint:
0 commit comments