Skip to content

Commit

Permalink
account: validate oauth state redirhost
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Oct 22, 2023
1 parent 2849924 commit 9182134
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import org.sql2o.Connection;
import org.sql2o.Sql2o;
import org.sql2o.Sql2oException;
Expand Down Expand Up @@ -97,6 +99,7 @@ public class AccountService
private final String oauthClientSecret;
private final String oauthCallback;
private final AuthFilter auth;
private final String redirHost;

@Autowired
public AccountService(
Expand All @@ -106,13 +109,15 @@ public AccountService(
@Value("${oauth.callback}") String oauthCallback,
@Value("${oauth.callback-snapshot}") String oauthSnapshotCallback,
@Value("#{servletContext.contextPath}") String contextPath,
AuthFilter auth
AuthFilter auth,
@Value("${oauth.redir-host}") String redirHost
)
{
this.sql2o = sql2o;
this.oauthClientId = oauthClientId;
this.oauthClientSecret = oauthClientSecret;
this.auth = auth;
this.redirHost = redirHost;

this.oauthCallback = contextPath.toLowerCase().contains("snapshot") ? oauthSnapshotCallback : oauthCallback;

Expand Down Expand Up @@ -243,6 +248,12 @@ public Object callback(
.addQueryParameter("username", userInfo.getEmail())
.addQueryParameter("sessionId", uuid.toString())
.build();

if (!redir.host().equals(redirHost))
{
logger.error("oauth state redirect to bad url/host {}/{}", state.getRedirectUrl(), redir.host());
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions http-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ oauth:
client-secret:
callback: https://api.runelite.net/oauth/
callback-snapshot: https://api.runelite.net/oauth-snapshot/
redir-host: runelite.net

# Redis client
redis:
Expand Down

0 comments on commit 9182134

Please sign in to comment.