-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1148 from SeasideSt/protectionfilters
Protectionfilters
- Loading branch information
Showing
36 changed files
with
174 additions
and
16 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
repository/Seaside-Core.package/WAAbstractProtectionFilter.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A protection filter protects the wrapped request handler, mostly useful to protect against session hijacking. See subclasses for different strategies. |
8 changes: 3 additions & 5 deletions
8
.../WAProtectionFilter.class/properties.json → ...actProtectionFilter.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
{ | ||
"commentStamp" : "lr 8/11/2009 10:56", | ||
"commentStamp" : "JohanBrichau 8/4/2019 07:41", | ||
"super" : "WARequestFilter", | ||
"category" : "Seaside-Core-Filter", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"remoteAddress" | ||
], | ||
"name" : "WAProtectionFilter", | ||
"instvars" : [ ], | ||
"name" : "WAAbstractProtectionFilter", | ||
"type" : "normal" | ||
} |
3 changes: 0 additions & 3 deletions
3
repository/Seaside-Core.package/WAProtectionFilter.class/README.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
repository/Seaside-Core.package/WAQueryFieldHandlerTrackingStrategy.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
repository/Seaside-Core.package/WARemoteAddressProtectionFilter.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The remote address protection filter ensures that the wrapped request handler only accepts requests from the same IP. Do add this filter to a WASession for example to avoid session hijacking, do not add it to static request handlers such as WAApplication or WADispatcher as this might restrict access to the handler if your IP changes. | ||
|
||
Note that checking for IP addresses is not bullet proof and should never be used as the sole security measure for a web application as IP addresses can be easily spoofed. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
repository/Seaside-Core.package/WARemoteAddressProtectionFilter.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"commentStamp" : "JohanBrichau 8/4/2019 07:26", | ||
"super" : "WAAbstractProtectionFilter", | ||
"category" : "Seaside-Core-Filter", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"remoteAddress" | ||
], | ||
"name" : "WARemoteAddressProtectionFilter", | ||
"type" : "normal" | ||
} |
7 changes: 7 additions & 0 deletions
7
repository/Seaside-Core.package/WASessionCookieProtectionFilter.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
The session cookie protection filter ensures that the wrapped request handler only accepts requests from the same browser session. This filter is specifically useful to protect session hijacking when using the (default) query field session tracking strategy. | ||
|
||
Because WAQueryFieldHandlerTrackingStrategy puts the Seaside session key in the url, a session can be easily hijacked by copying the url. This request filter prevents this by requiring a browser session cookie associated to the Seaside session. As a result, a copied Seaside url can only be used in the same browser session. | ||
|
||
The use of this filter, in combination with WAQueryFieldHandlerTrackingStrategy, keeps the ability for a user to open multiple sessions of the same Seaside application in a single browser, while removing easy session hijacking. A malicious user that wants to hijack the session now needs both the url and the cookie. | ||
|
||
The appropriate use of this filter is to add it to the session in the `initializeFilters` method of your session class. Only in this way, the session is protected from the first rendered application page onwards. See WASessionCookieProtectedSession class as an example. |
3 changes: 3 additions & 0 deletions
3
...y/Seaside-Core.package/WASessionCookieProtectionFilter.class/instance/browserSessionID.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
browserSessionID | ||
^ browserSessionID |
4 changes: 4 additions & 0 deletions
4
...-Core.package/WASessionCookieProtectionFilter.class/instance/browserSessionIDCookieKey.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
constants | ||
browserSessionIDCookieKey | ||
|
||
^ 'seaside_browser_session' |
4 changes: 4 additions & 0 deletions
4
...aside-Core.package/WASessionCookieProtectionFilter.class/instance/browserSessionIDSize.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
constants | ||
browserSessionIDSize | ||
|
||
^ 20 |
7 changes: 7 additions & 0 deletions
7
...ackage/WASessionCookieProtectionFilter.class/instance/createBrowserSessionIDCookieFor..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
private | ||
createBrowserSessionIDCookieFor: aRequestContext | ||
"Override this to customize cookie properties that fit your application needs" | ||
^ aRequestContext newCookie | ||
sameSite: 'Strict'; | ||
key: self browserSessionIDCookieKey; | ||
value: self browserSessionID |
15 changes: 15 additions & 0 deletions
15
...ry/Seaside-Core.package/WASessionCookieProtectionFilter.class/instance/handleFiltered..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
processing | ||
handleFiltered: aRequestContext | ||
"If the browserSessionID instvar is nil, we are a newly created session and should set our browser session id. | ||
Otherwise, verify the browser session id for the current request." | ||
self browserSessionID | ||
ifNil: [ self setBrowserSessionIDFor: aRequestContext ] | ||
ifNotNil: [ | ||
(self verifyBrowserSessionIDFor: aRequestContext) | ||
ifFalse: [ | ||
"If we carry a redirected url field, we have tried setting a cookie, which failed. Stop here to avoid infinite redirect. | ||
In the other case, respond with the forbidden status code" | ||
(self requestContext request queryFields includesKey: 'cookiecheck') | ||
ifTrue:[ self respondCookiesRequired: aRequestContext ] | ||
ifFalse: [ aRequestContext responseGenerator forbidden; respond ] ] ]. | ||
super handleFiltered: aRequestContext |
3 changes: 3 additions & 0 deletions
3
...ckage/WASessionCookieProtectionFilter.class/instance/renderCookiesRequiredStatementOn..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
processing | ||
renderCookiesRequiredStatementOn: html | ||
html text: 'Sorry, but this application requires cookies to be enabled' |
16 changes: 16 additions & 0 deletions
16
...de-Core.package/WASessionCookieProtectionFilter.class/instance/respondCookiesRequired..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
processing | ||
respondCookiesRequired: aRequestContext | ||
| dialog | | ||
dialog := WAHtmlCanvas builder | ||
fullDocument: true; | ||
rootBlock: [ :root | | ||
root | ||
beHtml5; | ||
title: 'Cookies Required' ]; | ||
render: [ :html | self renderCookiesRequiredStatementOn: html ]. | ||
aRequestContext | ||
respond: [ :response | | ||
response | ||
forbidden; | ||
contentType: WAMimeType textHtml; | ||
nextPutAll: dialog ] |
14 changes: 14 additions & 0 deletions
14
...de-Core.package/WASessionCookieProtectionFilter.class/instance/setBrowserSessionIDFor..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
private | ||
setBrowserSessionIDFor: aRequestContext | ||
"If there already is a browser session cookie, we reuse this one. | ||
This means we can have multiple sessions open in a single browser, because they share the browser session id." | ||
(aRequestContext request cookieAt: self browserSessionIDCookieKey) | ||
ifNotNil: [ :cookie | browserSessionID := cookie value ] | ||
ifNil: [ | ||
browserSessionID := (WAKeyGenerator current keyOfLength: self browserSessionIDSize). | ||
aRequestContext response | ||
addCookie: (self createBrowserSessionIDCookieFor: aRequestContext); | ||
redirectTo: (aRequestContext request url copy | ||
addField: self application trackingStrategy keyField value: self session key; | ||
addField: 'cookiecheck' value: nil; | ||
yourself) ] |
5 changes: 5 additions & 0 deletions
5
...Core.package/WASessionCookieProtectionFilter.class/instance/verifyBrowserSessionIDFor..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
private | ||
verifyBrowserSessionIDFor: requestContext | ||
| cookie | | ||
cookie := requestContext request cookieAt: self browserSessionIDCookieKey. | ||
^ cookie notNil and: [ cookie value = self browserSessionID ] |
13 changes: 13 additions & 0 deletions
13
repository/Seaside-Core.package/WASessionCookieProtectionFilter.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"commentStamp" : "JohanBrichau 8/24/2019 13:30", | ||
"super" : "WAAbstractProtectionFilter", | ||
"category" : "Seaside-Core-Filter", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"browserSessionID" | ||
], | ||
"name" : "WASessionCookieProtectionFilter", | ||
"type" : "normal" | ||
} |
Empty file.
4 changes: 4 additions & 0 deletions
4
...side-Examples.package/WASessionCookieProtectedSession.class/instance/initializeFilters.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
initialization | ||
initializeFilters | ||
super initializeFilters. | ||
self addFilter: WASessionCookieProtectionFilter new. |
11 changes: 11 additions & 0 deletions
11
repository/Seaside-Examples.package/WASessionCookieProtectedSession.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"commentStamp" : "", | ||
"super" : "WASession", | ||
"category" : "Seaside-Examples", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ ], | ||
"name" : "WASessionCookieProtectedSession", | ||
"type" : "normal" | ||
} |
Empty file.
3 changes: 3 additions & 0 deletions
3
repository/Seaside-Examples.package/WASessionProtectedCounter.class/class/handlerName.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
handlerName | ||
^ 'examples/sessionprotected-counter' |
5 changes: 5 additions & 0 deletions
5
repository/Seaside-Examples.package/WASessionProtectedCounter.class/class/initialize.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
initialization | ||
initialize | ||
| app | | ||
app := WAAdmin register: self asApplicationAt: self handlerName. | ||
app sessionClass: WASessionCookieProtectedSession |
4 changes: 4 additions & 0 deletions
4
repository/Seaside-Examples.package/WASessionProtectedCounter.class/instance/initialize.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
initialization | ||
initialize | ||
super initialize. | ||
counter := WACounter new |
4 changes: 4 additions & 0 deletions
4
...ory/Seaside-Examples.package/WASessionProtectedCounter.class/instance/renderContentOn..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rendering | ||
renderContentOn: html | ||
counter renderOn: html. | ||
html paragraph: 'I am the Counter example using WASessionCookieProtectionFilter so you cannot copy/paste the url in another browser to hijack my session. See the class comment of WASessionCookieProtectionFilter for more information.' |
13 changes: 13 additions & 0 deletions
13
repository/Seaside-Examples.package/WASessionProtectedCounter.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"commentStamp" : "", | ||
"super" : "WAExampleComponent", | ||
"category" : "Seaside-Examples-Misc", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"counter" | ||
], | ||
"name" : "WASessionProtectedCounter", | ||
"type" : "normal" | ||
} |
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...nctional.package/WAFilterFunctionalTest.class/instance/protectorByBrowserSessionCookie.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
actions | ||
protectorByBrowserSessionCookie | ||
| filter | | ||
"We could use #filterWith:during: but that requires Flow." | ||
filter := WASessionCookieProtectionFilter new. | ||
self session addFilter: filter. | ||
child inform: 'Open this page in a different browser by copying the complete URL. Seaside should reply with a forbidden message. Closing this dialog should remove the filter.' onAnswer: [ self session removeFilter: filter ] |
4 changes: 2 additions & 2 deletions
4
...unctionalTest.class/instance/protector.st → ...lass/instance/protectorByRemoteAddress.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
actions | ||
protector | ||
protectorByRemoteAddress | ||
| filter | | ||
"We could use #filterWith:during: but that requires Flow." | ||
filter := WAProtectionFilter new. | ||
filter := WARemoteAddressProtectionFilter new. | ||
self session addFilter: filter. | ||
child inform: 'Open this page on a different computer by copying the complete URL to a machine with a different IP address. Seaside should reply with a forbidden message. Closing this dialog should remove the filter.' onAnswer: [ self session removeFilter: filter ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
repository/Seaside-Tests-Functional.package/monticello.meta/version
This file was deleted.
Oops, something went wrong.