mirror of
https://github.com/Open-Argon/http.ar.git
synced 2026-10-28 09:43:55 +00:00
attempt to fix dos attack vulnerability
This commit is contained in:
1 parent
246f6a08d2
commit
4d3f01ef50
6 files changed
+19
-18
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"name": "http.ar",
|
||||
"version": "1.0.4"
|
||||
"version": "1.0.5"
|
||||
}
|
||||
@@ -48,10 +48,7 @@ let err404path = path.join([parent,"static", "404.html"])
|
||||
|
||||
app.use(http.static("/",path.join([parent,"static"])))
|
||||
|
||||
let getCanvas(req, res) = do
|
||||
res.json(canvas)
|
||||
|
||||
app.route('/get-canvas', null, getCanvas)
|
||||
app.route('/get-canvas', null, (req, res) = res.json({canvas:canvas, time:time.now()}))
|
||||
|
||||
let getCanvasUpdates(req, res) = do
|
||||
if ("lastTime" not in req.query) do
|
||||
@@ -63,7 +60,7 @@ let getCanvasUpdates(req, res) = do
|
||||
if (changes[i].time > lastTime) do
|
||||
filtered.append(changes[i])
|
||||
else break
|
||||
res.json(filtered)
|
||||
res.json({updates:filtered, time:time.now()})
|
||||
|
||||
app.route('/get-canvas-updates', null, getCanvasUpdates)
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ const addPixel = (x, y, colour) => {
|
||||
new Event("colour-change");
|
||||
|
||||
let pixels = [];
|
||||
let updatesSince = new Date();
|
||||
let updatesSince;
|
||||
|
||||
const resize = () => {
|
||||
const { innerWidth, innerHeight } = window;
|
||||
@@ -55,26 +55,25 @@ const draw = () => {
|
||||
const getCanvas = async () => {
|
||||
const resp = await fetch("/get-canvas");
|
||||
const data = await resp.json();
|
||||
pixels = data;
|
||||
updatesSince = data.time
|
||||
pixels = data.canvas;
|
||||
};
|
||||
|
||||
const getUpdates = async () => {
|
||||
const url = new URL("/get-canvas-updates", window.location.href);
|
||||
url.searchParams.append("lastTime", updatesSince.getTime());
|
||||
url.searchParams.append("lastTime", updatesSince);
|
||||
const resp = await fetch(url);
|
||||
const data = await resp.json();
|
||||
for (const update of data) {
|
||||
for (const update of data.updates) {
|
||||
addPixel(update.x, update.y, update.colour);
|
||||
}
|
||||
updatesSince = new Date();
|
||||
updatesSince = data.time
|
||||
};
|
||||
|
||||
canvas.addEventListener("click", async (e) => {
|
||||
const pixelsize = canvas.width / size.width;
|
||||
const x = Math.floor(e.offsetX / pixelsize);
|
||||
const y = Math.floor(e.offsetY / pixelsize);
|
||||
addPixel(x, y, currentColour);
|
||||
updatesSince = new Date();
|
||||
await fetch("/update-canvas", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -86,6 +85,7 @@ canvas.addEventListener("click", async (e) => {
|
||||
colour: currentColour,
|
||||
}),
|
||||
});
|
||||
getUpdates()
|
||||
});
|
||||
|
||||
resize();
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
[{"Name":"neon.ar","Version":"beta1.0.2","URL":"https://isotope.wbell.dev/isotope-download?name=neon.ar\u0026version=beta1.0.2","Remote":"isotope.wbell.dev"},{"Name":"url.ar","Version":"1.0.1","URL":"https://isotope.wbell.dev/isotope-download?version=1.0.1\u0026name=url.ar","Remote":"isotope.wbell.dev"}]
|
||||
[{"Name":"neon.ar","Version":"beta1.0.2","URL":"https://isotope.wbell.dev/isotope-download?name=neon.ar\u0026version=beta1.0.2","Remote":"isotope.wbell.dev"},{"Name":"url.ar","Version":"1.0.1","URL":"https://isotope.wbell.dev/isotope-download?name=url.ar\u0026version=1.0.1","Remote":"isotope.wbell.dev"}]
|
||||
@@ -11,6 +11,7 @@ let __initHeaders() = {"content-type": "text/html; charset=utf-8", "server": "ht
|
||||
let handle(routes, conn, onErr) = do
|
||||
try do
|
||||
let request = parseRequest.parse(conn)
|
||||
if (not request) return
|
||||
request.RemoteAddr = conn.RemoteAddr()
|
||||
let splitURL = url.split(request.path)
|
||||
request.path = splitURL.path
|
||||
@@ -86,9 +87,11 @@ let handle(routes, conn, onErr) = do
|
||||
response.headers["location"] = path
|
||||
response.send("")
|
||||
response.close() = do
|
||||
conn.close()
|
||||
for (i from 0 to request.on.end.length) do
|
||||
request.on.end[i]()
|
||||
try do
|
||||
conn.close()
|
||||
for (i from 0 to request.on.end.length) do
|
||||
request.on.end[i]()
|
||||
catch (_) do
|
||||
response.templateValues = {}
|
||||
response.renderTemplate(path, values) = do
|
||||
let keys = response.templateValues.keys()
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ let parse(conn) = do
|
||||
let split = headerData.to("string").split("\r\n")
|
||||
let requestLine = split[0].split(" ")
|
||||
if (requestLine.length != 3) do
|
||||
throwError("requestError","Invalid request line")
|
||||
if (conn.isClosed()) throwError("requestError","Invalid request line")
|
||||
return
|
||||
let method = requestLine[0]
|
||||
let path = requestLine[1]
|
||||
let version = requestLine[2]
|
||||
|
||||
Reference in new issue
Block a user