Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ export class YouMdParserImpl implements YouMdParser {
};
}

if (parsedUrl.username || parsedUrl.password) {
return {
profile: createEmptyProfile(),
success: false,
errors: [
{
code: "NETWORK_ERROR",
message: "Credentials in URL are not supported",
},
],
warnings: [],
};
}

const timeout = this.resolveFetchTimeout(fetchOptions?.timeout);
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeout);
Expand Down
12 changes: 12 additions & 0 deletions test/parser/loadFromUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ describe("loadFromUrl hardening", () => {
expect(result.errors.some((e) => e.code === "FILE_TOO_LARGE")).toBe(true);
});

it("rejects URLs containing embedded credentials", async () => {
const parser = createParser();
const fetchSpy = vi.spyOn(globalThis, "fetch");

const result = await parser.loadFromUrl("https://user:secret@example.com/profile.md");

expect(result.success).toBe(false);
expect(result.errors.some((e) => e.code === "NETWORK_ERROR")).toBe(true);
expect(result.errors[0]?.message).toContain("Credentials in URL are not supported");
expect(fetchSpy).not.toHaveBeenCalled();
});

it("falls back to default timeout when fetch timeout is invalid", async () => {
const parser = createParser();
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
Expand Down
Loading