mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-09-02 08:20:39 +00:00
Merge branch 'main' into main
This commit is contained in:
@@ -24,9 +24,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
|
||||
- run: npm install
|
||||
|
||||
@@ -44,16 +41,11 @@ jobs:
|
||||
|
||||
- name: Get changed files
|
||||
if: github.event_name == 'pull_request'
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const { execSync } = require("child_process")
|
||||
const { commits } = context.payload.pull_request
|
||||
const rawFiles = execSync(`git diff --name-only HEAD HEAD~${commits}`).toString()
|
||||
const files = rawFiles.split("\n").filter(Boolean)
|
||||
console.log(files)
|
||||
const jsonArray = JSON.stringify(files)
|
||||
core.exportVariable('CHANGED_FILES', jsonArray)
|
||||
run: |
|
||||
FILES=$(gh api --jq '[.[] | .filename]' /repos/{owner}/{repo}/pulls/${{ github.event.number }}/files)
|
||||
echo "CHANGED_FILES=$FILES" >> $GITHUB_ENV
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
|
||||
- name: Run tests
|
||||
run: npx ava tests/*.test.js
|
||||
run: npx ava tests/*.test.js --timeout=1m
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"owner": {
|
||||
"username": "noelpaton-og",
|
||||
"email": "noel27938@gmail.com"
|
||||
},
|
||||
"record": {
|
||||
"CNAME": "noelpaton-og.github.io"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"description": "Domain for redirection to angganix.is-a.dev",
|
||||
"owner": {
|
||||
"username": "angganix",
|
||||
"email": "angganix@gmail.com"
|
||||
},
|
||||
"record": {
|
||||
"URL": "https://angganix.is-a.dev"
|
||||
}
|
||||
}
|
||||
+16
-67
@@ -3,9 +3,7 @@ const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs
|
||||
.readdirSync(domainsPath)
|
||||
.filter((file) => file.endsWith(".json"));
|
||||
const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json"));
|
||||
|
||||
const domainCache = {};
|
||||
|
||||
@@ -15,15 +13,11 @@ function getDomainData(subdomain) {
|
||||
}
|
||||
|
||||
try {
|
||||
const data = fs.readJsonSync(
|
||||
path.join(domainsPath, `${subdomain}.json`),
|
||||
);
|
||||
const data = fs.readJsonSync(path.join(domainsPath, `${subdomain}.json`));
|
||||
domainCache[subdomain] = data; // Cache the domain data
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Failed to read JSON for ${subdomain}: ${error.message}`,
|
||||
);
|
||||
throw new Error(`Failed to read JSON for ${subdomain}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,30 +46,24 @@ t("Nested subdomains should not exist without a parent subdomain", (t) => {
|
||||
const parentSubdomain = getParentSubdomain(subdomain);
|
||||
t.true(
|
||||
parentSubdomain && files.includes(`${parentSubdomain}.json`),
|
||||
`${file}: Parent subdomain does not exist`,
|
||||
`${file}: Parent subdomain does not exist`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
t(
|
||||
"Nested subdomains should not exist if the parent subdomain has NS records",
|
||||
(t) => {
|
||||
files.forEach((file) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
t("Nested subdomains should not exist if the parent subdomain has NS records", (t) => {
|
||||
files.forEach((file) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
|
||||
if (subdomain.split(".").length > 1) {
|
||||
const parentSubdomain = getParentSubdomain(subdomain);
|
||||
const parentDomain = getDomainData(parentSubdomain);
|
||||
if (subdomain.split(".").length > 1) {
|
||||
const parentSubdomain = getParentSubdomain(subdomain);
|
||||
const parentDomain = getDomainData(parentSubdomain);
|
||||
|
||||
t.true(
|
||||
!parentDomain.record.NS,
|
||||
`${file}: Parent subdomain has NS records`,
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
t.true(!parentDomain.record.NS, `${file}: Parent subdomain has NS records`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
t("Nested subdomains should be owned by the parent subdomain's owner", (t) => {
|
||||
files.forEach((file) => {
|
||||
@@ -87,48 +75,9 @@ t("Nested subdomains should be owned by the parent subdomain's owner", (t) => {
|
||||
const parentDomain = getDomainData(parentSubdomain);
|
||||
|
||||
t.true(
|
||||
data.owner.username.toLowerCase() ===
|
||||
parentDomain.owner.username.toLowerCase(),
|
||||
`${file}: Owner does not match the parent subdomain`,
|
||||
data.owner.username.toLowerCase() === parentDomain.owner.username.toLowerCase(),
|
||||
`${file}: Owner does not match the parent subdomain`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
t("Subdomains containing an underscore can only have specific records", (t) => {
|
||||
files.forEach((file) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
|
||||
if (subdomain.includes("_")) {
|
||||
const data = getDomainData(subdomain);
|
||||
const recordKeys = Object.keys(data.record);
|
||||
|
||||
if (
|
||||
subdomain.startsWith("_acme-challenge.") ||
|
||||
subdomain.includes("._domainkey.")
|
||||
) {
|
||||
t.true(
|
||||
recordKeys.every((key) =>
|
||||
new Set(["TXT", "CNAME"]).has(key),
|
||||
),
|
||||
`${file}: This type of subdomain can only have TXT or CNAME records`,
|
||||
);
|
||||
} else if (
|
||||
subdomain.includes("._tcp.") ||
|
||||
subdomain.includes("._udp.")
|
||||
) {
|
||||
t.deepEqual(
|
||||
recordKeys,
|
||||
["SRV"],
|
||||
`${file}: This type of subdomain can only have SRV records`,
|
||||
);
|
||||
} else {
|
||||
t.deepEqual(
|
||||
recordKeys,
|
||||
["TXT"],
|
||||
`${file}: Subdomains with underscores can only have TXT records`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+2
-43
@@ -36,33 +36,6 @@ const reservedDomains = require("../util/reserved.json");
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs.readdirSync(domainsPath);
|
||||
|
||||
function expandReservedDomains(reserved) {
|
||||
const expandedList = [...reserved];
|
||||
|
||||
reserved.forEach((item) => {
|
||||
const rangeMatch = item.match(/\[(\d+)-(\d+)\]/);
|
||||
|
||||
if (rangeMatch) {
|
||||
const prefix = item.split("[")[0];
|
||||
const start = parseInt(rangeMatch[1], 10);
|
||||
const end = parseInt(rangeMatch[2], 10);
|
||||
|
||||
if (start < end) {
|
||||
for (let i = start; i <= end; i++) {
|
||||
expandedList.push(prefix + i);
|
||||
}
|
||||
expandedList.splice(expandedList.indexOf(item), 1);
|
||||
} else {
|
||||
throw new Error(`[util/reserved.json] Invalid range [${start}-${end}] in "${item}"`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return expandedList;
|
||||
}
|
||||
|
||||
const expandedReservedDomains = expandReservedDomains(reservedDomains);
|
||||
|
||||
function findDuplicateKeys(jsonString) {
|
||||
const keyPattern = /"([^"]+)"(?=\s*:)/g;
|
||||
const keys = [];
|
||||
@@ -105,9 +78,9 @@ async function validateFileName(t, file) {
|
||||
hostnameRegex,
|
||||
`${file}: FQDN must be 1-253 characters, use letters, numbers, dots, or hyphens, and not start or end with a hyphen.`
|
||||
);
|
||||
t.false(expandedReservedDomains.includes(subdomain), `${file}: Subdomain name is reserved`);
|
||||
t.false(reservedDomains.includes(subdomain), `${file}: Subdomain name is reserved`);
|
||||
t.true(
|
||||
!expandedReservedDomains.some((reserved) => subdomain.endsWith(`.${reserved}`)),
|
||||
!reservedDomains.some((reserved) => subdomain.endsWith(`.${reserved}`)),
|
||||
`${file}: Subdomain name is reserved`
|
||||
);
|
||||
|
||||
@@ -173,17 +146,3 @@ t("All files should have valid file names", async (t) => {
|
||||
t("All files should have valid required and optional fields", async (t) => {
|
||||
await Promise.all(files.map((file) => processFile(file, t)));
|
||||
});
|
||||
|
||||
t("Reserved domains file should be valid", (t) => {
|
||||
const subdomainRegex = /^_?[a-zA-Z0-9]+([-\.][a-zA-Z0-9]+)*(\[\d+-\d+\])?$/;
|
||||
|
||||
expandedReservedDomains.forEach((item, index) => {
|
||||
t.regex(
|
||||
item,
|
||||
subdomainRegex,
|
||||
`[util/reserved-domains.json] Invalid subdomain name "${item}" at index ${index}`
|
||||
);
|
||||
});
|
||||
|
||||
t.pass();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
const t = require("ava");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const trustedUsers = require("../util/trusted.json").map((u) => u.toLowerCase());
|
||||
|
||||
function getDomainData(subdomain) {
|
||||
try {
|
||||
const data = fs.readJsonSync(path.join(path.resolve("domains"), `${subdomain}.json`));
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to read JSON for ${subdomain}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
t("Users can only update their own subdomains", (t) => {
|
||||
if (process.env.PR_AUTHOR && process.env.CHANGED_FILES) {
|
||||
const changedFiles = JSON.parse(process.env.CHANGED_FILES);
|
||||
const prAuthor = process.env.PR_AUTHOR.toLowerCase();
|
||||
const changedJSONFiles = changedFiles
|
||||
.filter((file) => file.startsWith("domains/"))
|
||||
.map((file) => path.basename(file));
|
||||
|
||||
if (!changedJSONFiles || trustedUsers.includes(prAuthor)) return t.pass();
|
||||
if (process.env.PR_LABELS && process.env.PR_LABELS.includes("bypass-owner-check")) return t.pass();
|
||||
|
||||
changedJSONFiles.forEach((file) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
const data = getDomainData(subdomain);
|
||||
|
||||
t.true(
|
||||
data.owner.username.toLowerCase() === prAuthor,
|
||||
`${subdomain}: ${prAuthor} does not own ${subdomain}.is-a.dev`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
t.pass();
|
||||
});
|
||||
+9
-16
@@ -25,29 +25,22 @@ function validateProxiedRecords(t, data, file) {
|
||||
const recordTypes = Array.from(requiredRecordsToProxy).join(", ");
|
||||
|
||||
if (data.proxied) {
|
||||
const hasProxiedRecord = Object.keys(data.record).some((key) =>
|
||||
requiredRecordsToProxy.has(key),
|
||||
);
|
||||
const hasProxiedRecord = Object.keys(data.record).some((key) => requiredRecordsToProxy.has(key));
|
||||
|
||||
t.true(
|
||||
hasProxiedRecord,
|
||||
`${file}: Proxied is true but there are no records that can be proxied (${recordTypes} expected)`,
|
||||
`${file}: Proxied is true but there are no records that can be proxied (${recordTypes} expected)`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs
|
||||
.readdirSync(domainsPath)
|
||||
.filter((file) => file.endsWith(".json"));
|
||||
const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json"));
|
||||
|
||||
t(
|
||||
"Domains with proxy enabled must have at least one proxy-able record",
|
||||
(t) => {
|
||||
files.forEach((file) => {
|
||||
const domain = getDomainData(file);
|
||||
t("Domains with proxy enabled must have at least one proxy-able record", (t) => {
|
||||
files.forEach((file) => {
|
||||
const domain = getDomainData(file);
|
||||
|
||||
validateProxiedRecords(t, domain, file);
|
||||
});
|
||||
},
|
||||
);
|
||||
validateProxiedRecords(t, domain, file);
|
||||
});
|
||||
});
|
||||
|
||||
+58
-162
@@ -2,29 +2,14 @@ const t = require("ava");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const validRecordTypes = new Set([
|
||||
"A",
|
||||
"AAAA",
|
||||
"CAA",
|
||||
"CNAME",
|
||||
"DS",
|
||||
"MX",
|
||||
"NS",
|
||||
"SRV",
|
||||
"TXT",
|
||||
"URL",
|
||||
]);
|
||||
const hostnameRegex =
|
||||
/^(?=.{1,253}$)(?:(?:[_a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)\.)+[a-zA-Z]{2,63}$/;
|
||||
const ipv4Regex =
|
||||
/^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}$/;
|
||||
const validRecordTypes = new Set(["A", "AAAA", "CAA", "CNAME", "DS", "MX", "NS", "SRV", "TXT", "URL"]);
|
||||
const hostnameRegex = /^(?=.{1,253}$)(?:(?:[_a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)\.)+[a-zA-Z]{2,63}$/;
|
||||
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}$/;
|
||||
const ipv6Regex =
|
||||
/^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}$|^(?:[0-9a-fA-F]{1,4}:){1,7}:$|^(?:[0-9a-fA-F]{1,4}:){0,6}::(?:[0-9a-fA-F]{1,4}:){0,5}[0-9a-fA-F]{1,4}$/;
|
||||
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs
|
||||
.readdirSync(domainsPath)
|
||||
.filter((file) => file.endsWith(".json"));
|
||||
const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json"));
|
||||
|
||||
const domainCache = {};
|
||||
|
||||
@@ -53,7 +38,7 @@ function expandIPv6(ip) {
|
||||
segments = [
|
||||
...nonEmptySegments.slice(0, emptyIndex),
|
||||
...Array(missingSegments).fill("0000"),
|
||||
...nonEmptySegments.slice(emptyIndex),
|
||||
...nonEmptySegments.slice(emptyIndex)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -63,11 +48,7 @@ function expandIPv6(ip) {
|
||||
function validateIPv4(ip, proxied) {
|
||||
const parts = ip.split(".").map(Number);
|
||||
|
||||
if (
|
||||
parts.length !== 4 ||
|
||||
parts.some((part) => isNaN(part) || part < 0 || part > 255)
|
||||
)
|
||||
return false;
|
||||
if (parts.length !== 4 || parts.some((part) => isNaN(part) || part < 0 || part > 255)) return false;
|
||||
if (ip === "192.0.2.1" && proxied) return true;
|
||||
|
||||
return !(
|
||||
@@ -113,153 +94,100 @@ function validateRecordValues(t, data, file) {
|
||||
Object.entries(data.record).forEach(([key, value]) => {
|
||||
// General validation for arrays
|
||||
if (["A", "AAAA", "MX", "NS"].includes(key)) {
|
||||
t.true(
|
||||
Array.isArray(value),
|
||||
`${file}: Record value for ${key} should be an array`,
|
||||
);
|
||||
t.true(Array.isArray(value), `${file}: Record value for ${key} should be an array`);
|
||||
|
||||
value.forEach((record, idx) => {
|
||||
t.true(
|
||||
typeof record === "string",
|
||||
`${file}: Record value for ${key} should be a string at index ${idx}`,
|
||||
`${file}: Record value for ${key} should be a string at index ${idx}`
|
||||
);
|
||||
|
||||
if (key === "A") {
|
||||
t.true(
|
||||
ipv4Regex.test(record),
|
||||
`${file}: Invalid IPv4 address for ${key} at index ${idx}`,
|
||||
);
|
||||
t.true(ipv4Regex.test(record), `${file}: Invalid IPv4 address for ${key} at index ${idx}`);
|
||||
t.true(
|
||||
validateIPv4(record, data.proxied),
|
||||
`${file}: Invalid IPv4 address for ${key} at index ${idx}`,
|
||||
`${file}: Invalid IPv4 address for ${key} at index ${idx}`
|
||||
);
|
||||
} else if (key === "AAAA") {
|
||||
const expandedIPv6 = expandIPv6(record);
|
||||
t.true(
|
||||
ipv6Regex.test(expandedIPv6),
|
||||
`${file}: Invalid IPv6 address for ${key} at index ${idx}`,
|
||||
);
|
||||
t.true(
|
||||
validateIPv6(expandedIPv6),
|
||||
`${file}: Invalid IPv6 address for ${key} at index ${idx}`,
|
||||
);
|
||||
t.true(ipv6Regex.test(expandedIPv6), `${file}: Invalid IPv6 address for ${key} at index ${idx}`);
|
||||
t.true(validateIPv6(expandedIPv6), `${file}: Invalid IPv6 address for ${key} at index ${idx}`);
|
||||
} else if (["MX", "NS"].includes(key)) {
|
||||
t.true(
|
||||
isValidHostname(record),
|
||||
`${file}: Invalid hostname for ${key} at index ${idx}`,
|
||||
);
|
||||
t.true(isValidHostname(record), `${file}: Invalid hostname for ${key} at index ${idx}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// CNAME and URL validations
|
||||
if (["CNAME", "URL"].includes(key)) {
|
||||
t.true(
|
||||
typeof value === "string",
|
||||
`${file}: Record value for ${key} should be a string`,
|
||||
);
|
||||
t.true(typeof value === "string", `${file}: Record value for ${key} should be a string`);
|
||||
|
||||
if (key === "CNAME") {
|
||||
t.true(
|
||||
isValidHostname(value),
|
||||
`${file}: Invalid hostname for ${key}`,
|
||||
);
|
||||
t.true(isValidHostname(value), `${file}: Invalid hostname for ${key}`);
|
||||
t.true(value !== file, `${file}: CNAME cannot point to itself`);
|
||||
} else if (key === "URL") {
|
||||
t.true(
|
||||
value.startsWith("http://") || value.startsWith("https://"),
|
||||
`${file}: Record value for ${key} must start with http:// or https://`,
|
||||
);
|
||||
t.notThrows(
|
||||
() => new URL(value),
|
||||
`${file}: Invalid URL for ${key}`,
|
||||
`${file}: Record value for ${key} must start with http:// or https://`
|
||||
);
|
||||
t.notThrows(() => new URL(value), `${file}: Invalid URL for ${key}`);
|
||||
|
||||
const urlHost = new URL(value).host;
|
||||
const isSelfReferencing =
|
||||
file === "@.json"
|
||||
? urlHost === "is-a.dev"
|
||||
: urlHost === `${subdomain}.is-a.dev`;
|
||||
file === "@.json" ? urlHost === "is-a.dev" : urlHost === `${subdomain}.is-a.dev`;
|
||||
|
||||
t.false(
|
||||
isSelfReferencing,
|
||||
`${file}: URL cannot point to itself`,
|
||||
);
|
||||
t.false(isSelfReferencing, `${file}: URL cannot point to itself`);
|
||||
}
|
||||
}
|
||||
|
||||
// CAA, DS, SRV validations
|
||||
if (["CAA", "DS", "SRV"].includes(key)) {
|
||||
t.true(
|
||||
Array.isArray(value),
|
||||
`${file}: Record value for ${key} should be an array`,
|
||||
);
|
||||
t.true(Array.isArray(value), `${file}: Record value for ${key} should be an array`);
|
||||
|
||||
value.forEach((record, idx) => {
|
||||
t.true(
|
||||
typeof record === "object",
|
||||
`${file}: Record value for ${key} should be an object at index ${idx}`,
|
||||
`${file}: Record value for ${key} should be an object at index ${idx}`
|
||||
);
|
||||
|
||||
if (key === "CAA") {
|
||||
t.true(
|
||||
["issue", "issuewild", "iodef"].includes(record.tag),
|
||||
`${file}: Invalid tag for CAA at index ${idx}`,
|
||||
);
|
||||
t.true(
|
||||
typeof record.value === "string",
|
||||
`${file}: Invalid value for CAA at index ${idx}`,
|
||||
`${file}: Invalid tag for CAA at index ${idx}`
|
||||
);
|
||||
t.true(typeof record.value === "string", `${file}: Invalid value for CAA at index ${idx}`);
|
||||
t.true(
|
||||
isValidHostname(record.value) || record.value === ";",
|
||||
`${file}: Value must be a hostname or semicolon for CAA at index ${idx}`,
|
||||
`${file}: Value must be a hostname or semicolon for CAA at index ${idx}`
|
||||
);
|
||||
} else if (key === "DS") {
|
||||
t.true(
|
||||
Number.isInteger(record.key_tag) &&
|
||||
record.key_tag >= 0 &&
|
||||
record.key_tag <= 65535,
|
||||
`${file}: Invalid key_tag for DS at index ${idx}`,
|
||||
Number.isInteger(record.key_tag) && record.key_tag >= 0 && record.key_tag <= 65535,
|
||||
`${file}: Invalid key_tag for DS at index ${idx}`
|
||||
);
|
||||
t.true(
|
||||
Number.isInteger(record.algorithm) &&
|
||||
record.algorithm >= 0 &&
|
||||
record.algorithm <= 255,
|
||||
`${file}: Invalid algorithm for DS at index ${idx}`,
|
||||
Number.isInteger(record.algorithm) && record.algorithm >= 0 && record.algorithm <= 255,
|
||||
`${file}: Invalid algorithm for DS at index ${idx}`
|
||||
);
|
||||
t.true(
|
||||
Number.isInteger(record.digest_type) &&
|
||||
record.digest_type >= 0 &&
|
||||
record.digest_type <= 255,
|
||||
`${file}: Invalid digest_type for DS at index ${idx}`,
|
||||
);
|
||||
t.true(
|
||||
isValidHexadecimal(record.digest),
|
||||
`${file}: Invalid digest for DS at index ${idx}`,
|
||||
Number.isInteger(record.digest_type) && record.digest_type >= 0 && record.digest_type <= 255,
|
||||
`${file}: Invalid digest_type for DS at index ${idx}`
|
||||
);
|
||||
t.true(isValidHexadecimal(record.digest), `${file}: Invalid digest for DS at index ${idx}`);
|
||||
} else if (key === "SRV") {
|
||||
t.true(
|
||||
Number.isInteger(record.priority) &&
|
||||
record.priority >= 0 &&
|
||||
record.priority <= 65535,
|
||||
`${file}: Invalid priority for SRV at index ${idx}`,
|
||||
Number.isInteger(record.priority) && record.priority >= 0 && record.priority <= 65535,
|
||||
`${file}: Invalid priority for SRV at index ${idx}`
|
||||
);
|
||||
t.true(
|
||||
Number.isInteger(record.weight) &&
|
||||
record.weight >= 0 &&
|
||||
record.weight <= 65535,
|
||||
`${file}: Invalid weight for SRV at index ${idx}`,
|
||||
Number.isInteger(record.weight) && record.weight >= 0 && record.weight <= 65535,
|
||||
`${file}: Invalid weight for SRV at index ${idx}`
|
||||
);
|
||||
t.true(
|
||||
Number.isInteger(record.port) &&
|
||||
record.port >= 0 &&
|
||||
record.port <= 65535,
|
||||
`${file}: Invalid port for SRV at index ${idx}`,
|
||||
);
|
||||
t.true(
|
||||
isValidHostname(record.target),
|
||||
`${file}: Invalid target for SRV at index ${idx}`,
|
||||
Number.isInteger(record.port) && record.port >= 0 && record.port <= 65535,
|
||||
`${file}: Invalid port for SRV at index ${idx}`
|
||||
);
|
||||
t.true(isValidHostname(record.target), `${file}: Invalid target for SRV at index ${idx}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -268,60 +196,44 @@ function validateRecordValues(t, data, file) {
|
||||
if (key === "TXT") {
|
||||
const values = Array.isArray(value) ? value : [value];
|
||||
values.forEach((record, idx) => {
|
||||
t.true(
|
||||
typeof record === "string",
|
||||
`${file}: TXT record value should be a string at index ${idx}`,
|
||||
);
|
||||
t.true(typeof record === "string", `${file}: TXT record value should be a string at index ${idx}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (data.redirect_config) {
|
||||
const customPaths = Object.keys(
|
||||
data.redirect_config.custom_paths || {},
|
||||
);
|
||||
const customPaths = Object.keys(data.redirect_config.custom_paths || {});
|
||||
const pathRegex = /^\/[a-zA-Z0-9\-_\.\/]+(?<!\/)$/;
|
||||
|
||||
customPaths.forEach((customPath, idx) => {
|
||||
const customRedirectURL =
|
||||
data.redirect_config.custom_paths[customPath];
|
||||
const customRedirectURL = data.redirect_config.custom_paths[customPath];
|
||||
const urlMessage = `${file}: Custom path in redirect_config`;
|
||||
|
||||
// Validate the custom path
|
||||
t.true(
|
||||
pathRegex.test(customPath),
|
||||
`${urlMessage} must start with a slash, contain only alphanumeric characters, hyphens, underscores, periods, and slashes, and cannot end with a slash at index ${idx}`,
|
||||
`${urlMessage} must start with a slash, contain only alphanumeric characters, hyphens, underscores, periods, and slashes, and cannot end with a slash at index ${idx}`
|
||||
);
|
||||
t.true(
|
||||
customPath.length >= 2 && customPath.length <= 255,
|
||||
`${urlMessage} should be 2-255 characters long at index ${idx}`,
|
||||
`${urlMessage} should be 2-255 characters long at index ${idx}`
|
||||
);
|
||||
|
||||
// Validate the redirect URL
|
||||
t.true(
|
||||
data.record.URL !== customRedirectURL,
|
||||
`${urlMessage} should be different from the URL record at index ${idx}`,
|
||||
`${urlMessage} should be different from the URL record at index ${idx}`
|
||||
);
|
||||
t.true(
|
||||
customRedirectURL.startsWith("http://") ||
|
||||
customRedirectURL.startsWith("https://"),
|
||||
`${urlMessage} must start with http:// or https:// at index ${idx}`,
|
||||
);
|
||||
t.notThrows(
|
||||
() => new URL(customRedirectURL),
|
||||
`${urlMessage} contains an invalid URL at index ${idx}`,
|
||||
customRedirectURL.startsWith("http://") || customRedirectURL.startsWith("https://"),
|
||||
`${urlMessage} must start with http:// or https:// at index ${idx}`
|
||||
);
|
||||
t.notThrows(() => new URL(customRedirectURL), `${urlMessage} contains an invalid URL at index ${idx}`);
|
||||
|
||||
// Check for self-referencing redirects
|
||||
const urlHost = new URL(customRedirectURL).host;
|
||||
const isSelfReferencing =
|
||||
file === "@.json"
|
||||
? urlHost === "is-a.dev"
|
||||
: urlHost === `${subdomain}.is-a.dev`;
|
||||
t.false(
|
||||
isSelfReferencing,
|
||||
`${urlMessage} cannot point to itself at index ${idx}`,
|
||||
);
|
||||
const isSelfReferencing = file === "@.json" ? urlHost === "is-a.dev" : urlHost === `${subdomain}.is-a.dev`;
|
||||
t.false(isSelfReferencing, `${urlMessage} cannot point to itself at index ${idx}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -332,51 +244,35 @@ t("All files should have valid record types", (t) => {
|
||||
const recordKeys = Object.keys(data.record);
|
||||
|
||||
recordKeys.forEach((key) => {
|
||||
t.true(
|
||||
validateRecordType(key),
|
||||
`${file}: Invalid record type: ${key}`,
|
||||
);
|
||||
t.true(validateRecordType(key), `${file}: Invalid record type: ${key}`);
|
||||
});
|
||||
|
||||
// Record type combinations validation
|
||||
if (recordKeys.includes("CNAME") && !data.proxied) {
|
||||
t.is(
|
||||
recordKeys.length,
|
||||
1,
|
||||
`${file}: CNAME records cannot be combined with other records unless proxied`,
|
||||
);
|
||||
t.is(recordKeys.length, 1, `${file}: CNAME records cannot be combined with other records unless proxied`);
|
||||
}
|
||||
if (recordKeys.includes("NS")) {
|
||||
t.true(
|
||||
recordKeys.length === 1 ||
|
||||
(recordKeys.length === 2 && recordKeys.includes("DS")),
|
||||
`${file}: NS records cannot be combined with other records, except for DS records`,
|
||||
recordKeys.length === 1 || (recordKeys.length === 2 && recordKeys.includes("DS")),
|
||||
`${file}: NS records cannot be combined with other records, except for DS records`
|
||||
);
|
||||
}
|
||||
if (recordKeys.includes("DS")) {
|
||||
t.true(
|
||||
recordKeys.includes("NS"),
|
||||
`${file}: DS records must be combined with NS records`,
|
||||
);
|
||||
t.true(recordKeys.includes("NS"), `${file}: DS records must be combined with NS records`);
|
||||
}
|
||||
if (recordKeys.includes("URL")) {
|
||||
t.true(
|
||||
!recordKeys.includes("A") &&
|
||||
!recordKeys.includes("AAAA") &&
|
||||
!recordKeys.includes("CNAME"),
|
||||
`${file}: URL records cannot be combined with A, AAAA, or CNAME records`,
|
||||
!recordKeys.includes("A") && !recordKeys.includes("AAAA") && !recordKeys.includes("CNAME"),
|
||||
`${file}: URL records cannot be combined with A, AAAA, or CNAME records`
|
||||
);
|
||||
}
|
||||
if (data.redirect_config) {
|
||||
t.true(
|
||||
recordKeys.includes("URL") || data.proxied,
|
||||
`${file}: Redirect config must be combined with a URL record or the domain must be proxied`,
|
||||
`${file}: Redirect config must be combined with a URL record or the domain must be proxied`
|
||||
);
|
||||
if (data.redirect_config.redirect_paths) {
|
||||
t.true(
|
||||
recordKeys.includes("URL"),
|
||||
`${file}: redirect_config.redirect_paths requires a URL record`,
|
||||
);
|
||||
t.true(recordKeys.includes("URL"), `${file}: redirect_config.redirect_paths requires a URL record`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-22
@@ -3,24 +3,14 @@ const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const domainsPath = path.resolve("domains");
|
||||
const files = fs
|
||||
.readdirSync(domainsPath)
|
||||
.filter((file) => file.endsWith(".json"));
|
||||
|
||||
const bypassedUsernames = require("../util/bypassed.json").map((username) =>
|
||||
username.toLowerCase(),
|
||||
);
|
||||
const files = fs.readdirSync(domainsPath).filter((file) => file.endsWith(".json"));
|
||||
|
||||
function getDomainData(subdomain) {
|
||||
try {
|
||||
const data = fs.readJsonSync(
|
||||
path.join(domainsPath, `${subdomain}.json`),
|
||||
);
|
||||
const data = fs.readJsonSync(path.join(domainsPath, `${subdomain}.json`));
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Failed to read JSON for ${subdomain}: ${error.message}`,
|
||||
);
|
||||
throw new Error(`Failed to read JSON for ${subdomain}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,20 +21,15 @@ t("Users are limited to one single character subdomain", (t) => {
|
||||
const subdomain = file.replace(/\.json$/, "");
|
||||
const data = getDomainData(subdomain);
|
||||
|
||||
if (
|
||||
subdomain.length === 1 &&
|
||||
!bypassedUsernames.includes(data.owner.username.toLowerCase())
|
||||
) {
|
||||
if (subdomain.length === 1 && data.owner.username.toLowerCase() !== "is-a-dev") {
|
||||
results.push({
|
||||
subdomain,
|
||||
owner: data.owner.username.toLowerCase(),
|
||||
owner: data.owner.username.toLowerCase()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const duplicates = results.filter(
|
||||
(result) => results.filter((r) => r.owner === result.owner).length > 1,
|
||||
);
|
||||
const duplicates = results.filter((result) => results.filter((r) => r.owner === result.owner).length > 1);
|
||||
const output = duplicates.reduce((acc, curr) => {
|
||||
if (!acc[curr.owner]) {
|
||||
acc[curr.owner] = [];
|
||||
@@ -59,7 +44,7 @@ t("Users are limited to one single character subdomain", (t) => {
|
||||
0,
|
||||
Object.keys(output)
|
||||
.map((owner) => `${owner} - ${output[owner].join(", ")}`)
|
||||
.join("\n"),
|
||||
.join("\n")
|
||||
);
|
||||
|
||||
t.pass();
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
["is-a-dev", "wdhdev"]
|
||||
+40
-75
@@ -1,91 +1,66 @@
|
||||
[
|
||||
"_acme-challenge.www",
|
||||
"_atproto.www",
|
||||
"_discord.www",
|
||||
"_vercel.www",
|
||||
"acc",
|
||||
"account",
|
||||
"accounts",
|
||||
"admin",
|
||||
"admin[1-99]",
|
||||
"admins",
|
||||
"administrator",
|
||||
"administrators",
|
||||
"alert",
|
||||
"alerts",
|
||||
"api",
|
||||
"apis",
|
||||
"assets",
|
||||
"auth",
|
||||
"authentication",
|
||||
"authorisation",
|
||||
"authorise",
|
||||
"authorization",
|
||||
"authorize",
|
||||
"aux",
|
||||
"ad",
|
||||
"ads",
|
||||
"billing",
|
||||
"blog",
|
||||
"calendar",
|
||||
"cart",
|
||||
"catalog",
|
||||
"cdn",
|
||||
"chat",
|
||||
"checkout",
|
||||
"cname",
|
||||
"cname[1-99]",
|
||||
"co",
|
||||
"codeofconduct",
|
||||
"code-of-conduct",
|
||||
"com",
|
||||
"com[1-9]",
|
||||
"con",
|
||||
"confirm",
|
||||
"confirmation",
|
||||
"contribute",
|
||||
"contributing",
|
||||
"dash",
|
||||
"dashboard",
|
||||
"default",
|
||||
"dns",
|
||||
"doc",
|
||||
"documentation",
|
||||
"email",
|
||||
"emails",
|
||||
"error",
|
||||
"errors",
|
||||
"event",
|
||||
"events",
|
||||
"example",
|
||||
"feedback",
|
||||
"file",
|
||||
"file[1-9999]",
|
||||
"files",
|
||||
"finance",
|
||||
"forgot",
|
||||
"forgot-password",
|
||||
"gtld",
|
||||
"guest",
|
||||
"help",
|
||||
"helpdesk",
|
||||
"helper",
|
||||
"helper[1-99]",
|
||||
"helpers",
|
||||
"hostmaster",
|
||||
"http",
|
||||
"https",
|
||||
"info",
|
||||
"infos",
|
||||
"int",
|
||||
"internal",
|
||||
"legal",
|
||||
"license",
|
||||
"login",
|
||||
"logout",
|
||||
"lpt[1-9]",
|
||||
"lpt1",
|
||||
"lpt2",
|
||||
"lpt3",
|
||||
"lpt4",
|
||||
"lpt5",
|
||||
"lpt6",
|
||||
"lpt7",
|
||||
"lpt8",
|
||||
"lpt9",
|
||||
"m",
|
||||
"mail",
|
||||
"maintainer",
|
||||
"maintainers",
|
||||
"marketing",
|
||||
"media",
|
||||
"mobile",
|
||||
"mod",
|
||||
"mod[1-99]",
|
||||
"mods",
|
||||
"moderator",
|
||||
"moderators",
|
||||
"net",
|
||||
@@ -94,75 +69,65 @@
|
||||
"noc",
|
||||
"notification",
|
||||
"notifications",
|
||||
"notify",
|
||||
"ns",
|
||||
"ns[1-99]",
|
||||
"nul",
|
||||
"ns1",
|
||||
"ns2",
|
||||
"ns3",
|
||||
"ns4",
|
||||
"ns5",
|
||||
"ns6",
|
||||
"ns7",
|
||||
"ns8",
|
||||
"ns9",
|
||||
"oauth",
|
||||
"oauth[1-99]",
|
||||
"official",
|
||||
"operations",
|
||||
"ops",
|
||||
"org",
|
||||
"organisation",
|
||||
"owner",
|
||||
"pay",
|
||||
"payment",
|
||||
"payments",
|
||||
"portal",
|
||||
"postmaster",
|
||||
"preview",
|
||||
"private",
|
||||
"prod",
|
||||
"production",
|
||||
"recovery",
|
||||
"redirect",
|
||||
"registrar",
|
||||
"registry",
|
||||
"reset",
|
||||
"reset-password",
|
||||
"root",
|
||||
"sales",
|
||||
"schedule",
|
||||
"secure",
|
||||
"security",
|
||||
"service",
|
||||
"services",
|
||||
"session",
|
||||
"sessions",
|
||||
"shop",
|
||||
"signin",
|
||||
"signout",
|
||||
"signup",
|
||||
"srv",
|
||||
"srv[1-99]",
|
||||
"staff",
|
||||
"staging",
|
||||
"static",
|
||||
"statistics",
|
||||
"stats",
|
||||
"status",
|
||||
"store",
|
||||
"superuser",
|
||||
"support",
|
||||
"sys",
|
||||
"system",
|
||||
"teams",
|
||||
"test",
|
||||
"test[1-9999]",
|
||||
"termsofservice",
|
||||
"terms-of-service",
|
||||
"tld",
|
||||
"terms",
|
||||
"token",
|
||||
"tokens",
|
||||
"tos",
|
||||
"txt",
|
||||
"txt[1-9999]",
|
||||
"url",
|
||||
"url[1-9999]",
|
||||
"user",
|
||||
"users",
|
||||
"webmail",
|
||||
"webmaster",
|
||||
"whois",
|
||||
"www[1-99]",
|
||||
"ww",
|
||||
"www1",
|
||||
"www2",
|
||||
"www3",
|
||||
"www4",
|
||||
"www5",
|
||||
"www6",
|
||||
"www7",
|
||||
"www8",
|
||||
"www9",
|
||||
"wwww",
|
||||
"your-domain-name"
|
||||
]
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[
|
||||
"DEV-DIBSTER",
|
||||
"iostpa",
|
||||
"is-a-dev-bot",
|
||||
"orangci",
|
||||
"Stef-00012",
|
||||
"wdhdev"
|
||||
]
|
||||
Reference in New Issue
Block a user