Adding support to persist variables in Redis
This commit is contained in:
parent
18e4d2ba4e
commit
d955ddfe82
24 changed files with 397 additions and 120 deletions
|
@ -1,17 +1,17 @@
|
|||
import Axios from "axios";
|
||||
import ipaddr from 'ipaddr.js';
|
||||
import { Resolver } from 'dns';
|
||||
import { promisify } from 'util';
|
||||
import {LocalUrlError} from "./LocalUrlError";
|
||||
import {ITiledMap} from "@workadventure/tiled-map-type-guard";
|
||||
import {isTiledMap} from "@workadventure/tiled-map-type-guard/dist";
|
||||
import ipaddr from "ipaddr.js";
|
||||
import { Resolver } from "dns";
|
||||
import { promisify } from "util";
|
||||
import { LocalUrlError } from "./LocalUrlError";
|
||||
import { ITiledMap } from "@workadventure/tiled-map-type-guard";
|
||||
import { isTiledMap } from "@workadventure/tiled-map-type-guard/dist";
|
||||
|
||||
class MapFetcher {
|
||||
async fetchMap(mapUrl: string): Promise<ITiledMap> {
|
||||
// Before trying to make the query, let's verify the map is actually on the open internet (and not a local test map)
|
||||
|
||||
if (await this.isLocalUrl(mapUrl)) {
|
||||
throw new LocalUrlError('URL for map "'+mapUrl+'" targets a local map');
|
||||
throw new LocalUrlError('URL for map "' + mapUrl + '" targets a local map');
|
||||
}
|
||||
|
||||
// Note: mapUrl is provided by the client. A possible attack vector would be to use a rogue DNS server that
|
||||
|
@ -22,12 +22,12 @@ class MapFetcher {
|
|||
// - We make sure we are only passing "GET" requests
|
||||
// - The result of the query is never displayed to the end user
|
||||
const res = await Axios.get(mapUrl, {
|
||||
maxContentLength: 50*1024*1024, // Max content length: 50MB. Maps should not be bigger
|
||||
maxContentLength: 50 * 1024 * 1024, // Max content length: 50MB. Maps should not be bigger
|
||||
timeout: 10000, // Timeout after 10 seconds
|
||||
});
|
||||
|
||||
if (!isTiledMap(res.data)) {
|
||||
throw new Error('Invalid map format for map '+mapUrl);
|
||||
throw new Error("Invalid map format for map " + mapUrl);
|
||||
}
|
||||
|
||||
return res.data;
|
||||
|
@ -39,7 +39,7 @@ class MapFetcher {
|
|||
*/
|
||||
private async isLocalUrl(url: string): Promise<boolean> {
|
||||
const urlObj = new URL(url);
|
||||
if (urlObj.hostname === 'localhost' || urlObj.hostname.endsWith('.localhost')) {
|
||||
if (urlObj.hostname === "localhost" || urlObj.hostname.endsWith(".localhost")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ class MapFetcher {
|
|||
|
||||
for (const address of addresses) {
|
||||
const addr = ipaddr.parse(address);
|
||||
if (addr.range() !== 'unicast') {
|
||||
if (addr.range() !== "unicast") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue