Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webapp-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CS-214
ul2024
webapp-lib
Merge requests
!35
server: Protect against cross-origin websocket requests
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
server: Protect against cross-origin websocket requests
cpc/websocket-origin
into
main
Overview
19
Commits
4
Pipelines
0
Changes
4
Merged
Clément Pit-Claudel
requested to merge
cpc/websocket-origin
into
main
6 months ago
Overview
19
Commits
4
Pipelines
0
Changes
4
Expand
0
0
Merge request reports
Compare
main
version 6
172bcc26
6 months ago
version 5
cfcd863f
6 months ago
version 4
7eb9c770
6 months ago
version 3
383856de
6 months ago
version 2
43c76ef0
6 months ago
version 1
73354969
6 months ago
main (base)
and
version 4
latest version
a8cf4b49
4 commits,
6 months ago
version 6
172bcc26
10 commits,
6 months ago
version 5
cfcd863f
8 commits,
6 months ago
version 4
7eb9c770
7 commits,
6 months ago
version 3
383856de
6 commits,
6 months ago
version 2
43c76ef0
1 commit,
6 months ago
version 1
73354969
1 commit,
6 months ago
4 files
+
142
−
8
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
jvm/src/main/scala/cs214/webapp/server/decorators/originValidation.scala
0 → 100644
+
41
−
0
Options
package
cs214.webapp.server.decorators
import
cask.model.Response
import
cask.router.
{
Decorator
}
import
cask.router.Result
/** Decorator to validate the origin of the request.
* Cask Decorators enforce strict matching type signatures
* with the core function they are decorating.
* So for each new Return type T, a new Decorator class
* extending originValidation must be created.
* The only method to override is constructForbiddenResponse
* which might be different for each Return type T.
*
*/
private
class
originValidation
[
T
]
extends
Decorator
[
Any
,
T
,
Any
]
{
def
wrapFunction
(
ctx
:
cask.Request
,
delegate
:
Delegate
)
:
Result
[
T
]
=
{
// Check if the Origin header is valid
val
isSourceValid
=
ctx
.
headers
.
get
(
"host"
).
flatMap
(
_
.
headOption
).
exists
:
host
=>
ctx
.
headers
.
get
(
"origin"
).
flatMap
(
_
.
headOption
).
exists
:
origin
=>
origin
==
s
"http://$host"
||
origin
==
s
"https://$host"
if
(
isSourceValid
)
{
// Call the core logic
delegate
(
Map
.
empty
)
}
else
{
// Return a 403 Forbidden response
constructForbiddenResponse
.
asInstanceOf
[
Result
[
T
]]
}
}
def
constructForbiddenResponse
:
Result
[
T
]
=
???
}
/* WebSocket origin validation */
class
originValidationWebSocket
extends
originValidation
[
cask.endpoints.WebsocketResult
]
{
override
def
constructForbiddenResponse
:
Result
[
cask.endpoints.WebsocketResult
]
=
{
Result
.
Success
(
new
cask
.
endpoints
.
WebsocketResult
.
Response
(
cask
.
Response
(
"Forbidden"
,
403
)))
}
}
\ No newline at end of file
Loading