Skip to content

Commit

Permalink
safer implem for #2023
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Nov 6, 2024
1 parent e56ba8f commit 5d31e58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions otoroshi/app/env/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,12 @@ class Env(
.getOptionalWithFileSupport[Int]("app.exposed-ports.https")
.getOrElse(httpsPort)

lazy val bestExposedPort: String = if (exposedRootSchemeIsHttps) {
exposedHttpsPort
} else {
exposedHttpPort
}

lazy val proxyState = new NgProxyState(this)

lazy val http2ClientProxyEnabled = configuration
Expand Down
4 changes: 2 additions & 2 deletions otoroshi/app/gateway/handlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,8 @@ class GatewayRequestHandler(
Results.Unauthorized(Json.obj("error" -> "unauthorized")).vfuture
}
case Success(token) => {
if (rnd == Option(token.getClaim("r").asString()).getOrElse("--")) {
val id = Option(token.getClaim("i").asString()).getOrElse("--")
if (rnd == Option(token.getClaim("r").asString()).map(v => env.aesDecrypt(v)).getOrElse("--")) {
val id = Option(token.getClaim("i").asString()).map(v => env.aesDecrypt(v)).getOrElse("--")
Option(token.getClaim("k").asString()).getOrElse("--") match {
case "apikey" => {
env.proxyState.apikey(id) match {
Expand Down
6 changes: 3 additions & 3 deletions otoroshi/app/utils/infotoken.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ object InfoTokenHelper {
val rnd = IdGenerator.token(16)
val token: String = JWT.create()
.withClaim("k", kind)
.withClaim("i", id)
.withClaim("r", rnd)
.withClaim("i", env.aesEncrypt(id))
.withClaim("r", env.aesEncrypt(rnd))
.withIssuedAt(DateTime.now().toDate)
.withExpiresAt(DateTime.now().plus(secComTtl.toMillis).toDate)
.sign(env.sha256Alg)
Expand All @@ -53,7 +53,7 @@ object InfoTokenHelper {
exp = DateTime.now().plus(secComTtl.toMillis).toDate.getTime,
iat = DateTime.now().toDate.getTime,
jti = IdGenerator.uuid
).withClaim("url", s"${env.rootScheme}${env.adminApiExposedHost}/.well-known/otoroshi/consumers/${rnd}?t=${token}")
).withClaim("url", s"${env.rootScheme}${env.adminApiExposedHost}${env.bestExposedPort}/.well-known/otoroshi/consumers/${rnd}?t=${token}")
}
case SecComInfoTokenVersion.Legacy => {
OtoroshiClaim(
Expand Down

0 comments on commit 5d31e58

Please sign in to comment.