mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-13 13:37:31 -07:00
[backend] Limit node-fetch responses to a reasonable length in all places
This commit is contained in:
parent
5c659b1306
commit
630d6bdbe5
5 changed files with 11 additions and 2 deletions
|
@ -88,7 +88,6 @@ export async function getResponse(args: {
|
||||||
body?: string;
|
body?: string;
|
||||||
headers: Record<string, string>;
|
headers: Record<string, string>;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
size?: number;
|
|
||||||
redirect?: RequestRedirect;
|
redirect?: RequestRedirect;
|
||||||
}) {
|
}) {
|
||||||
const timeout = args.timeout || 10 * 1000;
|
const timeout = args.timeout || 10 * 1000;
|
||||||
|
@ -103,7 +102,7 @@ export async function getResponse(args: {
|
||||||
headers: args.headers,
|
headers: args.headers,
|
||||||
body: args.body,
|
body: args.body,
|
||||||
timeout,
|
timeout,
|
||||||
size: args.size || 10 * 1024 * 1024,
|
size: 10 * 1024 * 1024,
|
||||||
agent: getAgentByUrl,
|
agent: getAgentByUrl,
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
redirect: args.redirect
|
redirect: args.redirect
|
||||||
|
|
|
@ -56,6 +56,8 @@ import {
|
||||||
import { RecursionLimiter } from "@/models/repositories/user-profile.js";
|
import { RecursionLimiter } from "@/models/repositories/user-profile.js";
|
||||||
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
import { UserConverter } from "@/server/api/mastodon/converters/user.js";
|
||||||
|
|
||||||
|
import fetch from "node-fetch";
|
||||||
|
|
||||||
const logger = apLogger;
|
const logger = apLogger;
|
||||||
|
|
||||||
const nameLength = 128;
|
const nameLength = 128;
|
||||||
|
@ -271,6 +273,7 @@ export async function createPerson(
|
||||||
try {
|
try {
|
||||||
let data = await fetch(person.followers, {
|
let data = await fetch(person.followers, {
|
||||||
headers: { Accept: "application/json" },
|
headers: { Accept: "application/json" },
|
||||||
|
size: 1024 * 1024
|
||||||
});
|
});
|
||||||
let json_data = JSON.parse(await data.text());
|
let json_data = JSON.parse(await data.text());
|
||||||
|
|
||||||
|
@ -286,6 +289,7 @@ export async function createPerson(
|
||||||
try {
|
try {
|
||||||
let data = await fetch(person.following, {
|
let data = await fetch(person.following, {
|
||||||
headers: { Accept: "application/json" },
|
headers: { Accept: "application/json" },
|
||||||
|
size: 1024 * 1024
|
||||||
});
|
});
|
||||||
let json_data = JSON.parse(await data.text());
|
let json_data = JSON.parse(await data.text());
|
||||||
|
|
||||||
|
@ -529,6 +533,7 @@ export async function updatePerson(
|
||||||
try {
|
try {
|
||||||
let data = await fetch(person.followers, {
|
let data = await fetch(person.followers, {
|
||||||
headers: { Accept: "application/json" },
|
headers: { Accept: "application/json" },
|
||||||
|
size: 1024 * 1024
|
||||||
});
|
});
|
||||||
let json_data = JSON.parse(await data.text());
|
let json_data = JSON.parse(await data.text());
|
||||||
|
|
||||||
|
@ -544,6 +549,7 @@ export async function updatePerson(
|
||||||
try {
|
try {
|
||||||
let data = await fetch(person.following, {
|
let data = await fetch(person.following, {
|
||||||
headers: { Accept: "application/json" },
|
headers: { Accept: "application/json" },
|
||||||
|
size: 1024 * 1024
|
||||||
});
|
});
|
||||||
let json_data = JSON.parse(await data.text());
|
let json_data = JSON.parse(await data.text());
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
},
|
},
|
||||||
body: JSON.stringify(jsonBody),
|
body: JSON.stringify(jsonBody),
|
||||||
agent: getAgentByUrl,
|
agent: getAgentByUrl,
|
||||||
|
size: 10 * 1024 * 1024
|
||||||
});
|
});
|
||||||
|
|
||||||
const json = (await res.json()) as {
|
const json = (await res.json()) as {
|
||||||
|
@ -114,6 +115,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
Accept: "application/json, */*",
|
Accept: "application/json, */*",
|
||||||
},
|
},
|
||||||
body: params,
|
body: params,
|
||||||
|
size: 10 * 1024 * 1024,
|
||||||
// TODO
|
// TODO
|
||||||
//timeout: 10000,
|
//timeout: 10000,
|
||||||
agent: getAgentByUrl,
|
agent: getAgentByUrl,
|
||||||
|
|
|
@ -199,6 +199,7 @@ async function fetchFaviconUrl(
|
||||||
// TODO
|
// TODO
|
||||||
//timeout: 10000,
|
//timeout: 10000,
|
||||||
agent: getAgentByUrl,
|
agent: getAgentByUrl,
|
||||||
|
size: 1024 * 1024
|
||||||
});
|
});
|
||||||
|
|
||||||
if (favicon.ok) {
|
if (favicon.ok) {
|
||||||
|
|
|
@ -85,6 +85,7 @@ export const request = async (
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
|
size: 10 * 1024 * 1024,
|
||||||
body: JSON.stringify(Object.assign(auth, params)),
|
body: JSON.stringify(Object.assign(auth, params)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue