Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify whether API key auth is required #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions config-instance.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ bannedHostnames = [
'evil.com'
]

# Specify whether connections need API key
authorizationRequired = true

###
# MySQL is used for Logging wnen it is enabled
###
Expand Down
13 changes: 7 additions & 6 deletions src/message-handlers/initialise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import HostnameAssignedMessage from '../messages/hostname-assigned-message';
import config from '../../config';
import Proxy from '../proxy';
import HostnameAlreadyTakenMessage from '../messages/hostname-already-taken';
import InvalidSubscriptionMessage from '../messages/invalid-subscription-message';
import addClientLog from '../metrics/add-client-log';
import { bannedClientIds } from '../../security/banned-client-ids';
import { INDEX_OF_NOT_FOUND } from '../../constants';
import { bannedIps } from '../../security/banned-ips';
import { bannedHostnames } from '../../security/banned-hostnames';
import ReservedDomain from '../model/reserved-domain';
import { addReservedDomain } from '../repository/reserved-subdomain-repository';
import { DOMAIN_ALREADY_RESERVED, ERROR, SUCCESS, TOO_MANY_DOMAINS, reserveDomain } from '../reserved-domain/reserved-domain';
import DomainAlreadyReserved from '../messages/domain-already-reserved';
import TooManyDomains from '../messages/domain-reservation-error';
Expand All @@ -25,11 +23,14 @@ const { verify } = require('reverse-dns-lookup');

export default async function initialise(message: InitialiseMessage, websocket: HostipWebSocket) {
let subdomain = generateRandomSubdomain(websocket);
const authorized = await authorize(message, websocket, subdomain);

if (config.server.authorizationRequired) {
const authorized = await authorize(message, websocket, subdomain);

if (authorized === false) {
// You shall not pass
return false;
if (authorized === false) {
// You shall not pass
return false;
}
}

// By default use a random subdomain unless the subscription is valid and a subdomain is passed
Expand Down