fix: isLocalResourse for proxy (#103)

GHSA-4c78-229v-hf6m
This commit is contained in:
Artemy Egorov 2024-03-05 21:53:40 +03:00 committed by GitHub
parent a7fdaf80fd
commit f241a46e05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "txtdot", "name": "txtdot",
"version": "1.6.0", "version": "1.6.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "txtdot", "name": "txtdot",
"version": "1.6.0", "version": "1.6.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@fastify/static": "^6.12.0", "@fastify/static": "^6.12.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "txtdot", "name": "txtdot",
"version": "1.6.0", "version": "1.6.1",
"private": true, "private": true,
"description": "txtdot is an HTTP proxy that parses only text, links and pictures from pages reducing internet bandwidth usage, removing ads and heavy scripts", "description": "txtdot is an HTTP proxy that parses only text, links and pictures from pages reducing internet bandwidth usage, removing ads and heavy scripts",
"main": "dist/app.js", "main": "dist/app.js",

View File

@ -2,11 +2,18 @@ import { FastifyInstance } from 'fastify';
import { IProxySchema, ProxySchema } from '../../types/requests/browser'; import { IProxySchema, ProxySchema } from '../../types/requests/browser';
import axios from '../../types/axios'; import axios from '../../types/axios';
import isLocalResource from '../../utils/islocal';
import { LocalResourceError } from '../../errors/main';
export default async function proxyRoute(fastify: FastifyInstance) { export default async function proxyRoute(fastify: FastifyInstance) {
fastify.get<IProxySchema>( fastify.get<IProxySchema>(
'/proxy', '/proxy',
{ schema: ProxySchema }, { schema: ProxySchema },
async (request, reply) => { async (request, reply) => {
if (await isLocalResource(new URL(request.query.url))) {
throw new LocalResourceError();
}
const response = await axios.get(request.query.url); const response = await axios.get(request.query.url);
const mime: string | undefined = const mime: string | undefined =
response.headers['content-type']?.toString(); response.headers['content-type']?.toString();