Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Masqr.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ async function MasqFail(req, res) {
if (!req.headers.host) {
return
}
if (!/^[a-zA-Z0-9.\-:]+$/.test(req.headers.host)) {
return
}
const unsafeSuffix = req.headers.host + ".html"
const safeSuffix = path.normalize(unsafeSuffix).replace(/^(\.\.(\/|\\|$))+/, "")
const safeJoin = path.join(process.cwd() + "/Masqrd", safeSuffix)
const safeJoin = path.join(process.cwd(), "Masqrd", path.basename(unsafeSuffix))
try {
await fs.promises.access(safeJoin)
const FailLocal = await fs.promises.readFile(safeJoin, "utf8")
Expand Down
23 changes: 18 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from "node:fs";
import http from "node:http";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { createBareServer } from "@nebula-services/bare-server-node";
import chalk from "chalk";
import cookieParser from "cookie-parser";
import cors from "cors";
import express from "express";
import basicAuth from "express-basic-auth";
import mime from "mime";
Expand All @@ -14,7 +14,7 @@ import config from "./config.js";

console.log(chalk.yellow("🚀 Starting server..."));

const __dirname = process.cwd();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const server = http.createServer();
const app = express();
const bareServer = createBareServer("/ca/");
Expand Down Expand Up @@ -69,7 +69,7 @@ app.get("/e/*", async (req, res, next) => {
const data = Buffer.from(await asset.arrayBuffer());
const ext = path.extname(reqTarget);
const no = [".unityweb"];
const contentType = no.includes(ext) ? "application/octet-stream" : mime.getType(ext);
const contentType = no.includes(ext) ? "application/octet-stream" : (mime.getType(ext) ?? "application/octet-stream");

cache.set(req.path, { data, contentType, timestamp: Date.now() });
res.writeHead(200, { "Content-Type": contentType });
Expand All @@ -91,7 +91,6 @@ app.use(express.urlencoded({ extended: true }));
} */

app.use(express.static(path.join(__dirname, "static")));
app.use("/ca", cors({ origin: true }));

const routes = [
{ path: "/b", file: "apps.html" },
Expand All @@ -115,11 +114,25 @@ app.use((req, res, next) => {

app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).sendFile(path.join(__dirname, "static", "404.html"));
res.status(500).sendFile(path.join(__dirname, "static", "500.html"));
});

server.on("request", (req, res) => {
if (bareServer.shouldRoute(req)) {
const origin = req.headers.origin;
if (typeof origin === "string" && origin.length > 0) {
res.setHeader("Access-Control-Allow-Origin", origin);
res.setHeader("Vary", "Origin");
} else {
res.setHeader("Access-Control-Allow-Origin", "*");
}
res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
if (req.method === "OPTIONS") {
res.statusCode = 204;
res.end();
return;
}
bareServer.routeRequest(req, res);
} else {
app(req, res);
Expand Down
39 changes: 39 additions & 0 deletions static/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="referrer" content="no-referrer" />
<meta http-equiv="X-Content-Type-Options" content="nosniff" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" id="tab-favicon" href="/favicon.png" />
<title id="t">Home</title>
<link rel="stylesheet" href="/assets/css/global.css?v=6" />
<link rel="stylesheet" href="/assets/css/error.css?v=2" />
<link rel="stylesheet" href="/assets/css/nav.css?v=01" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
</head>

<body>
<div class="f-nav"></div>
<div class="main error">
<h1>500</h1>
<h3>Internal server error.</h3>
<p>Something went wrong on our end. Try again in a moment.</p>
<button class="one" type="button" onclick="window.location.href = '/';">
Go Back Home
</button>
<button class="two" type="button" onclick="window.location.href = 'https://discord.gg/interstellar'">
Join our Discord (Direct)
</button>
<button class="three" type="button" onclick="go('https://discord.gg/interstellar')">
Join our Discord (Proxied)
</button>
</div>
</body>
<script src="/assets/js/index-3.js"></script>
<script src="/assets/mathematics/bundle.js?v=2025-04-15"></script>
<script src="/assets/mathematics/config.js?v=2025-04-15"></script>
<script src="/assets/js/m1.js"></script>

</html>