-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
101 additions
and
11,899 deletions.
There are no files selected for viewing
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
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
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,40 @@ | ||
package org.thp.cortex.services | ||
|
||
import javax.inject.{ Inject, Provider, Singleton } | ||
|
||
import play.api.Logger | ||
import play.api.http.SessionConfiguration | ||
import play.api.libs.crypto.CSRFTokenSigner | ||
import play.api.mvc.RequestHeader | ||
import play.filters.csrf.CSRF.{ ErrorHandler ⇒ CSRFErrorHandler, TokenProvider } | ||
import play.filters.csrf.CSRFConfig | ||
|
||
import akka.stream.Materializer | ||
|
||
object CSRFFilter { | ||
private[CSRFFilter] lazy val logger = Logger(getClass) | ||
|
||
def shouldProtect(request: RequestHeader): Boolean = { | ||
val isLogin = request.uri.startsWith("/api/login") | ||
val isApi = request.uri.startsWith("/api") | ||
val isInSession = request.session.data.nonEmpty | ||
val check = !isLogin && isApi && isInSession | ||
logger.debug(s"[csrf] uri ${request.uri} (isLogin=$isLogin, isApi=$isApi, isInSession=$isInSession): ${if (check) "" else "don't"} check") | ||
check | ||
} | ||
|
||
} | ||
|
||
@Singleton | ||
class CSRFFilter @Inject() ( | ||
config: Provider[CSRFConfig], | ||
tokenSignerProvider: Provider[CSRFTokenSigner], | ||
sessionConfiguration: SessionConfiguration, | ||
tokenProvider: TokenProvider, | ||
errorHandler: CSRFErrorHandler)(mat: Materializer) | ||
extends play.filters.csrf.CSRFFilter( | ||
config.get.copy(shouldProtect = CSRFFilter.shouldProtect), | ||
tokenSignerProvider.get, | ||
sessionConfiguration, | ||
tokenProvider, | ||
errorHandler)(mat) |
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
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
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 +1 @@ | ||
version in ThisBuild := "2.0.1" | ||
version in ThisBuild := "2.0.2" |
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ bower_components/ | |
.tmp/ | ||
true!ng-annotate/ | ||
dist/ | ||
package-lock.json | ||
config/manifest.json |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.