mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
validateHeaderCompliance (#145)
Co-authored-by: WantClue <wantclue@users.noreply.github.com>
This commit is contained in:
co-authored by
WantClue
parent
8b2bea702a
commit
9bf3dde862
@@ -353,6 +353,12 @@ export class StratumV1Client {
|
||||
private async initStratum() {
|
||||
this.stratumInitialized = true;
|
||||
|
||||
if (this.validateHeaderCompliance(this.clientSubscription.userAgent)) {
|
||||
console.log(`Non compliant connection from userAgent: ${this.clientSubscription.userAgent}`);
|
||||
await this.socket.end();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (this.clientSubscription.userAgent) {
|
||||
case 'cpuminer': {
|
||||
this.sessionDifficulty = 0.1;
|
||||
@@ -653,6 +659,18 @@ export class StratumV1Client {
|
||||
return number;
|
||||
}
|
||||
|
||||
private validateHeaderCompliance(userAgent: string): boolean {
|
||||
const headerCompliance = this.configService.get<string>('COMPLIANT_HEADERS');
|
||||
if (!headerCompliance || headerCompliance.trim() === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const complianceList = headerCompliance.split(',').map(ua => ua.trim().toLowerCase());
|
||||
const userAgentLower = userAgent.toLowerCase();
|
||||
|
||||
return complianceList.some(compliant => compliant.length > 0 && userAgentLower.includes(compliant));
|
||||
}
|
||||
|
||||
private async write(message: string): Promise<boolean> {
|
||||
try {
|
||||
if (!this.socket.destroyed && !this.socket.writableEnded) {
|
||||
|
||||
Reference in New Issue
Block a user