forked from Qortal/qortal
Disallow local (loopback address) requests when using the gateway
This removes the possibility of some locally running javascript in a website or app requesting unvetted data via the local gateway.
This commit is contained in:
parent
b7a0a7eea4
commit
ce56cd2b16
@ -50,6 +50,17 @@ public abstract class Security {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void disallowLoopbackRequests(HttpServletRequest request) {
|
||||||
|
try {
|
||||||
|
InetAddress remoteAddr = InetAddress.getByName(request.getRemoteAddr());
|
||||||
|
if (remoteAddr.isLoopbackAddress()) {
|
||||||
|
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.UNAUTHORIZED, "Local requests not allowed");
|
||||||
|
}
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ApiKey getApiKey(HttpServletRequest request) {
|
public static ApiKey getApiKey(HttpServletRequest request) {
|
||||||
ApiKey apiKey = ApiService.getInstance().getApiKey();
|
ApiKey apiKey = ApiService.getInstance().getApiKey();
|
||||||
if (apiKey == null) {
|
if (apiKey == null) {
|
||||||
|
@ -27,6 +27,8 @@ public class GatewayResource {
|
|||||||
@SecurityRequirement(name = "apiKey")
|
@SecurityRequirement(name = "apiKey")
|
||||||
public HttpServletResponse getPathByName(@PathParam("name") String name,
|
public HttpServletResponse getPathByName(@PathParam("name") String name,
|
||||||
@PathParam("path") String inPath) {
|
@PathParam("path") String inPath) {
|
||||||
|
// Block requests from localhost, to prevent websites/apps from running javascript that fetches unvetted data
|
||||||
|
Security.disallowLoopbackRequests(request);
|
||||||
return this.get(name, ResourceIdType.NAME, Service.WEBSITE, inPath, null, "", true, true);
|
return this.get(name, ResourceIdType.NAME, Service.WEBSITE, inPath, null, "", true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +36,8 @@ public class GatewayResource {
|
|||||||
@Path("{name}")
|
@Path("{name}")
|
||||||
@SecurityRequirement(name = "apiKey")
|
@SecurityRequirement(name = "apiKey")
|
||||||
public HttpServletResponse getIndexByName(@PathParam("name") String name) {
|
public HttpServletResponse getIndexByName(@PathParam("name") String name) {
|
||||||
|
// Block requests from localhost, to prevent websites/apps from running javascript that fetches unvetted data
|
||||||
|
Security.disallowLoopbackRequests(request);
|
||||||
return this.get(name, ResourceIdType.NAME, Service.WEBSITE, "/", null, "", true, true);
|
return this.get(name, ResourceIdType.NAME, Service.WEBSITE, "/", null, "", true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user