mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
fix: validate public IP response
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import z from 'zod';
|
||||
import { StreamProxyConfig } from '../db/schemas.js';
|
||||
import {
|
||||
Cache,
|
||||
@@ -107,6 +108,16 @@ export abstract class BaseProxy {
|
||||
const data = await response.json();
|
||||
const publicIp = this.getPublicIpFromResponse(data);
|
||||
|
||||
const { error, success } = z
|
||||
.union([z.ipv4(), z.ipv6()])
|
||||
.safeParse(publicIp);
|
||||
if (error || !success) {
|
||||
logger.error(
|
||||
`IP Response of ${publicIp} could not be parsed as a valid IP`
|
||||
);
|
||||
throw new Error(`Proxy did not respond with a valid public IP`);
|
||||
}
|
||||
|
||||
if (publicIp && cache) {
|
||||
await cache.set(cacheKey, publicIp, Env.PROXY_IP_CACHE_TTL);
|
||||
} else {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Cache,
|
||||
} from '../utils/index.js';
|
||||
import path from 'path';
|
||||
import z from 'zod';
|
||||
|
||||
const logger = createLogger('builtin');
|
||||
|
||||
@@ -85,6 +86,16 @@ export class BuiltinProxy extends BaseProxy {
|
||||
|
||||
const publicIp = await response.text();
|
||||
|
||||
const { error, success } = z
|
||||
.union([z.ipv4(), z.ipv6()])
|
||||
.safeParse(publicIp);
|
||||
if (error || !success) {
|
||||
logger.error(
|
||||
`IP Response of ${publicIp} could not be parsed as a valid IP`
|
||||
);
|
||||
throw new Error(`Proxy did not respond with a valid public IP`);
|
||||
}
|
||||
|
||||
if (publicIp && cache) {
|
||||
await cache.set(cacheKey, publicIp, Env.PROXY_IP_CACHE_TTL);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user