Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX #553 #554

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions otoroshi/app/controllers/Auth0Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ class AuthController(BackOfficeActionAuth: BackOfficeActionAuth,
.getQueryString("redirect")
.getOrElse(s"${req.theProtocol}://${req.theHost}${req.relativeUri}") match {
case "urn:ietf:wg:oauth:2.0:oob" => {
val redirection = s"${req.theProtocol}://${req.theHost}/.well-known/otoroshi/login?sessionId=${user.randomId}&redirectTo=urn:ietf:wg:oauth:2.0:oob&host=${req.theHost}&cp=${auth
.cookieSuffix(descriptor)}&ma=${auth.sessionMaxAge}&httpOnly=${auth.sessionCookieValues.httpOnly}&secure=${auth.sessionCookieValues.secure}"
val hash = env.sign(redirection)
FastFuture.successful(
Redirect(
s"${req.theProtocol}://${req.theHost}/.well-known/otoroshi/login?sessionId=${user.randomId}&redirectTo=urn:ietf:wg:oauth:2.0:oob&host=${req.theHost}&cp=${auth
.cookieSuffix(descriptor)}&ma=${auth.sessionMaxAge}&httpOnly=${auth.sessionCookieValues.httpOnly}&secure=${auth.sessionCookieValues.secure}"
).removingFromSession(s"pa-redirect-after-login-${auth.cookieSuffix(descriptor)}",
"desc")
Redirect(s"$redirection&hash=$hash")
.removingFromSession(s"pa-redirect-after-login-${auth.cookieSuffix(descriptor)}", "desc")
.withCookies(
env.createPrivateSessionCookies(req.theHost, user.randomId, descriptor, auth): _*
)
Expand All @@ -129,11 +129,15 @@ class AuthController(BackOfficeActionAuth: BackOfficeActionAuth,
val scheme = url.getProtocol
val setCookiesRedirect = url.getPort match {
case -1 =>
s"$scheme://$host/.well-known/otoroshi/login?sessionId=${user.randomId}&redirectTo=$redirectTo&host=$host&cp=${auth
val redirection = s"$scheme://$host/.well-known/otoroshi/login?sessionId=${user.randomId}&redirectTo=$redirectTo&host=$host&cp=${auth
.cookieSuffix(descriptor)}&ma=${auth.sessionMaxAge}&httpOnly=${auth.sessionCookieValues.httpOnly}&secure=${auth.sessionCookieValues.secure}"
val hash = env.sign(redirection)
s"$redirection&hash=$hash"
case port =>
s"$scheme://$host:$port/.well-known/otoroshi/login?sessionId=${user.randomId}&redirectTo=$redirectTo&host=$host&cp=${auth
val redirection = s"$scheme://$host:$port/.well-known/otoroshi/login?sessionId=${user.randomId}&redirectTo=$redirectTo&host=$host&cp=${auth
.cookieSuffix(descriptor)}&ma=${auth.sessionMaxAge}&httpOnly=${auth.sessionCookieValues.httpOnly}&secure=${auth.sessionCookieValues.secure}"
val hash = env.sign(redirection)
s"$redirection&hash=$hash"
}
FastFuture.successful(
Redirect(setCookiesRedirect)
Expand Down Expand Up @@ -200,25 +204,29 @@ class AuthController(BackOfficeActionAuth: BackOfficeActionAuth,
routes.PrivateAppsController.home().absoluteURL(env.exposedRootSchemeIsHttps)
) match {
case "urn:ietf:wg:oauth:2.0:oob" => {
val redirection = s"${req.theProtocol}://${req.theHost}/.well-known/otoroshi/login?sessionId=${paUser.randomId}&redirectTo=urn:ietf:wg:oauth:2.0:oob&host=${req.theHost}&cp=${auth
.cookieSuffix(descriptor)}&ma=${auth.sessionMaxAge}&httpOnly=${auth.sessionCookieValues.httpOnly}&secure=${auth.sessionCookieValues.secure}"
val hash = env.sign(redirection)
Redirect(
s"${req.theProtocol}://${req.theHost}/.well-known/otoroshi/login?sessionId=${paUser.randomId}&redirectTo=urn:ietf:wg:oauth:2.0:oob&host=${req.theHost}&cp=${auth
.cookieSuffix(descriptor)}&ma=${auth.sessionMaxAge}&httpOnly=${auth.sessionCookieValues.httpOnly}&secure=${auth.sessionCookieValues.secure}"
s"$redirection&hash=$hash"
).removingFromSession(s"pa-redirect-after-login-${auth.cookieSuffix(descriptor)}", "desc")
.withCookies(env.createPrivateSessionCookies(req.theHost, user.randomId, descriptor, auth): _*)
}
case redirectTo => {
val url = new java.net.URL(redirectTo)
val host = url.getHost
val scheme = url.getProtocol
val path = url.getPath
val query = Option(url.getQuery).map(q => s"?$q").getOrElse(s"")
val setCookiesRedirect = url.getPort match {
case -1 =>
s"$scheme://$host/.well-known/otoroshi/login?sessionId=${paUser.randomId}&redirectTo=$redirectTo&host=$host&cp=${auth
val redirection = s"$scheme://$host/.well-known/otoroshi/login?sessionId=${paUser.randomId}&redirectTo=$redirectTo&host=$host&cp=${auth
.cookieSuffix(descriptor)}&ma=${auth.sessionMaxAge}&httpOnly=${auth.sessionCookieValues.httpOnly}&secure=${auth.sessionCookieValues.secure}"
val hash = env.sign(redirection)
s"$redirection&hash=$hash"
case port =>
s"$scheme://$host:$port/.well-known/otoroshi/login?sessionId=${paUser.randomId}&redirectTo=$redirectTo&host=$host&cp=${auth
val redirection = s"$scheme://$host:$port/.well-known/otoroshi/login?sessionId=${paUser.randomId}&redirectTo=$redirectTo&host=$host&cp=${auth
.cookieSuffix(descriptor)}&ma=${auth.sessionMaxAge}&httpOnly=${auth.sessionCookieValues.httpOnly}&secure=${auth.sessionCookieValues.secure}"
val hash = env.sign(redirection)
s"$redirection&hash=$hash"
}
if (webauthn) {
Ok(Json.obj("location" -> setCookiesRedirect))
Expand Down
54 changes: 33 additions & 21 deletions otoroshi/app/gateway/handlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -322,27 +322,39 @@ class GatewayRequestHandler(snowMonkey: SnowMonkey,
val maOpt: Option[Int] = req.queryString.get("ma").map(_.last).map(_.toInt)
val httpOnlyOpt: Option[Boolean] = req.queryString.get("httpOnly").map(_.last).map(_.toBoolean)
val secureOpt: Option[Boolean] = req.queryString.get("secure").map(_.last).map(_.toBoolean)
//todo: test hash path
(redirectToOpt, sessionIdOpt, hostOpt, cookiePrefOpt, maOpt, httpOnlyOpt, secureOpt) match {
case (Some("urn:ietf:wg:oauth:2.0:oob"), Some(sessionId), Some(host), Some(cp), ma, httpOnly, secure) =>
FastFuture.successful(
Ok(views.html.otoroshi.token(env.signPrivateSessionId(sessionId), env)).withCookies(
env.createPrivateSessionCookiesWithSuffix(host, sessionId, cp, ma.getOrElse(86400), SessionCookieValues(httpOnly.getOrElse(true), secure.getOrElse(true))): _*
)
)
case (Some(redirectTo), Some(sessionId), Some(host), Some(cp), ma, httpOnly, secure) =>
FastFuture.successful(
Redirect(redirectTo).withCookies(
env.createPrivateSessionCookiesWithSuffix(host, sessionId, cp, ma.getOrElse(86400), SessionCookieValues(httpOnly.getOrElse(true), secure.getOrElse(true))): _*
)
)
case _ =>
Errors.craftResponseResult("Missing parameters",
BadRequest,
req,
None,
Some("errors.missing.parameters"),
attrs = TypedMap.empty)
val hashOpt: Option[String] = req.queryString.get("hash").map(_.last)

(hashOpt.map(h => env.sign(req.theUrl.replace(s"&hash=$h", ""))), hashOpt) match {
case (Some(hashedUrl), Some(hash)) if hashedUrl == hash =>
(redirectToOpt, sessionIdOpt, hostOpt, cookiePrefOpt, maOpt, httpOnlyOpt, secureOpt) match {
case (Some("urn:ietf:wg:oauth:2.0:oob"), Some(sessionId), Some(host), Some(cp), ma, httpOnly, secure) =>
FastFuture.successful(
Ok(views.html.otoroshi.token(env.signPrivateSessionId(sessionId), env)).withCookies(
env.createPrivateSessionCookiesWithSuffix(host, sessionId, cp, ma.getOrElse(86400), SessionCookieValues(httpOnly.getOrElse(true), secure.getOrElse(true))): _*
)
)
case (Some(redirectTo), Some(sessionId), Some(host), Some(cp), ma, httpOnly, secure) =>
FastFuture.successful(
Redirect(redirectTo).withCookies(
env.createPrivateSessionCookiesWithSuffix(host, sessionId, cp, ma.getOrElse(86400), SessionCookieValues(httpOnly.getOrElse(true), secure.getOrElse(true))): _*
)
)
case _ =>
Errors.craftResponseResult("Missing parameters",
BadRequest,
req,
None,
Some("errors.missing.parameters"),
attrs = TypedMap.empty)
}
case (_, _) =>
logger.warn(s"Unsecure redirection from privateApps login to ${redirectToOpt.getOrElse("no url")}")
Errors.craftResponseResult("Invalid redirection url",
BadRequest,
req,
None,
Some("errors.invalid.redirection.url"),
attrs = TypedMap.empty)
}
}

Expand Down
1 change: 1 addition & 0 deletions otoroshi/conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<logger name="otoroshi-ssl-trust-manager" level="INFO" />
<logger name="otoroshi-ssl-provider" level="INFO" />
<logger name="otoroshi-cluster" level="INFO" />
<logger name="otoroshi-auth-controller" level="INFO" />

<!-- Off these ones as they are annoying, and anyway we manage configuration ourselves -->
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
Expand Down