Disallow any kind of website/app/data rendering when localAuthBypassEnabled is enabled.

This allows node operators to return their authentication to the legacy rules (local requests allowed), without introducing javascript vulnerabilities. The websites, apps, etc are just prevented from loading, to avoid the risk of any API calls from javascript.
This commit is contained in:
CalDescent 2022-01-12 19:32:52 +00:00
parent ade977e416
commit f44c21ce59
2 changed files with 16 additions and 0 deletions

View File

@ -64,6 +64,19 @@ public abstract class Security {
} }
} }
public static void disallowLoopbackRequestsIfAuthBypassEnabled(HttpServletRequest request) {
if (Settings.getInstance().isLocalAuthBypassEnabled()) {
try {
InetAddress remoteAddr = InetAddress.getByName(request.getRemoteAddr());
if (remoteAddr.isLoopbackAddress()) {
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.UNAUTHORIZED, "Local requests not allowed when localAuthBypassEnabled is enabled in settings");
}
} catch (UnknownHostException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.UNAUTHORIZED);
}
}
}
public static void requirePriorAuthorization(HttpServletRequest request, String resourceId, Service service, String identifier) { public static void requirePriorAuthorization(HttpServletRequest request, String resourceId, Service service, String identifier) {
ArbitraryDataResource resource = new ArbitraryDataResource(resourceId, null, service, identifier); ArbitraryDataResource resource = new ArbitraryDataResource(resourceId, null, service, identifier);
if (!ArbitraryDataRenderManager.getInstance().isAuthorized(resource)) { if (!ArbitraryDataRenderManager.getInstance().isAuthorized(resource)) {

View File

@ -100,6 +100,7 @@ public class RenderResource {
@SecurityRequirement(name = "apiKey") @SecurityRequirement(name = "apiKey")
public boolean authorizeResource(@HeaderParam(Security.API_KEY_HEADER) String apiKey, @PathParam("resourceId") String resourceId) { public boolean authorizeResource(@HeaderParam(Security.API_KEY_HEADER) String apiKey, @PathParam("resourceId") String resourceId) {
Security.checkApiCallAllowed(request); Security.checkApiCallAllowed(request);
Security.disallowLoopbackRequestsIfAuthBypassEnabled(request);
ArbitraryDataResource resource = new ArbitraryDataResource(resourceId, null, null, null); ArbitraryDataResource resource = new ArbitraryDataResource(resourceId, null, null, null);
ArbitraryDataRenderManager.getInstance().addToAuthorizedResources(resource); ArbitraryDataRenderManager.getInstance().addToAuthorizedResources(resource);
return true; return true;
@ -112,6 +113,7 @@ public class RenderResource {
@PathParam("service") Service service, @PathParam("service") Service service,
@PathParam("resourceId") String resourceId) { @PathParam("resourceId") String resourceId) {
Security.checkApiCallAllowed(request); Security.checkApiCallAllowed(request);
Security.disallowLoopbackRequestsIfAuthBypassEnabled(request);
ArbitraryDataResource resource = new ArbitraryDataResource(resourceId, null, service, null); ArbitraryDataResource resource = new ArbitraryDataResource(resourceId, null, service, null);
ArbitraryDataRenderManager.getInstance().addToAuthorizedResources(resource); ArbitraryDataRenderManager.getInstance().addToAuthorizedResources(resource);
return true; return true;
@ -125,6 +127,7 @@ public class RenderResource {
@PathParam("resourceId") String resourceId, @PathParam("resourceId") String resourceId,
@PathParam("identifier") String identifier) { @PathParam("identifier") String identifier) {
Security.checkApiCallAllowed(request); Security.checkApiCallAllowed(request);
Security.disallowLoopbackRequestsIfAuthBypassEnabled(request);
ArbitraryDataResource resource = new ArbitraryDataResource(resourceId, null, service, identifier); ArbitraryDataResource resource = new ArbitraryDataResource(resourceId, null, service, identifier);
ArbitraryDataRenderManager.getInstance().addToAuthorizedResources(resource); ArbitraryDataRenderManager.getInstance().addToAuthorizedResources(resource);
return true; return true;