change traverse-api to not use KaiAuthDocuments

This commit is contained in:
zkldi
2021-06-01 21:24:08 +01:00
parent e46bc295b0
commit ac7a8d9ae7
2 changed files with 6 additions and 11 deletions
@@ -8,12 +8,7 @@ import { TraverseKaiAPI } from "./traverse-api";
const logger = CreateLogCtx(__filename);
const fakeAuth = {
userID: 1,
refreshToken: "foo",
service: "FLO" as const,
token: "bar",
};
const fakeAuth = "bar";
/**
* Async Generator To Array
@@ -1,7 +1,7 @@
import { KtLogger } from "../../../../logger/logger";
import ScoreImportFatalError from "../../../framework/score-importing/score-import-error";
import nodeFetch from "../../../../../utils/fetch";
import { KaiAuthDocument } from "kamaitachi-common";
import { VERSION_STR } from "../../../../constants/version";
/**
* Traverses a Kai-like personal_bests api.
@@ -14,7 +14,7 @@ import { KaiAuthDocument } from "kamaitachi-common";
export async function* TraverseKaiAPI(
baseUrl: string,
subUrl: string,
authDoc: KaiAuthDocument,
token: string,
logger: KtLogger,
fetch = nodeFetch
) {
@@ -22,13 +22,12 @@ export async function* TraverseKaiAPI(
let url = `${baseUrl}${subUrl}`;
while (fetchMoreData) {
// Rough SSRF check - KAI apis could potentially get us to perform
// Rough SSRF check - KAI-like apis could potentially get us to perform
// SSRF. We check if the origin of the next request is exactly the
// original, expected, base URL.
const origin = new URL(url).origin;
if (origin !== baseUrl) {
// this might be critical, to be honest.
logger.severe(`${baseUrl} attempted SSRF with url ${url}?`);
throw new ScoreImportFatalError(500, `${baseUrl} returned invalid data.`);
}
@@ -40,7 +39,8 @@ export async function* TraverseKaiAPI(
// eslint-disable-next-line no-await-in-loop
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${authDoc.token}`,
Authorization: `Bearer ${token}`,
"User-Agent": `Kamaitachi/${VERSION_STR}`,
},
});