Skip to content

Commit

Permalink
init whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
3Kmfi6HP committed Feb 15, 2024
1 parent 93043b5 commit e8cdb49
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion _worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ let proxyIP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)];

let dohURL = 'https://sky.rethinkdns.com/1:-Pf_____9_8A_AMAIgE8kMABVDDmKOHTAKg='; // https://cloudflare-dns.com/dns-query or https://dns.google/dns-query

// Array of allowed addresses
let allowedAddresses = ['www.google.com', 'whoer.net', 'speed.cloudflare.com'];
// v2board api environment variables (optional) deprecated, please use planetscale.com instead

if (!isValidUUID(userID)) {
Expand All @@ -20,7 +22,7 @@ if (!isValidUUID(userID)) {
export default {
/**
* @param {import("@cloudflare/workers-types").Request} request
* @param {{UUID: string, PROXYIP: string, DNS_RESOLVER_URL: string, NODE_ID: int, API_HOST: string, API_TOKEN: string}} env
* @param {{UUID: string, PROXYIP: string, DNS_RESOLVER_URL: string, NODE_ID: int, API_HOST: string, API_TOKEN: string, ALLOW_ED_ADDR: string}} env
* @param {import("@cloudflare/workers-types").ExecutionContext} ctx
* @returns {Promise<Response>}
*/
Expand All @@ -30,6 +32,7 @@ export default {
userID = env.UUID || userID;
proxyIP = env.PROXYIP || proxyIP;
dohURL = env.DNS_RESOLVER_URL || dohURL;
allowedAddresses = env.ALLOW_ED_ADDR || allowedAddresses;
let userID_Path = userID;
if (userID.includes(',')) {
userID_Path = userID.split(',')[0];
Expand Down Expand Up @@ -249,6 +252,11 @@ async function handleTCPOutBound(remoteSocket, addressRemote, portRemote, rawCli
* @returns {Promise<import("@cloudflare/workers-types").Socket>} A Promise that resolves to the connected socket.
*/
async function connectAndWrite(address, port) {
// Check if the address is allowed
if (!allowedAddresses.includes(address)) {
throw new Error('Connection to this address is not allowed');
}

/** @type {import("@cloudflare/workers-types").Socket} */
const tcpSocket = connect({
hostname: address,
Expand Down

0 comments on commit e8cdb49

Please sign in to comment.