mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-26 14:01:16 -07:00
only try http(s) urls
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import cache from "memory-cache";
|
||||
|
||||
import { parseFeed } from "./utils";
|
||||
import { httpUrl, parseFeed } from "./utils";
|
||||
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import createLogger from "utils/logger";
|
||||
@@ -18,12 +18,11 @@ export default async function feedProxyHandler(req, res) {
|
||||
return res.status(400).json({ error: "Missing feed URL" });
|
||||
}
|
||||
|
||||
let url;
|
||||
try {
|
||||
url = new URL(widget.url);
|
||||
} catch {
|
||||
const href = httpUrl(widget.url);
|
||||
if (!href) {
|
||||
return res.status(400).json({ error: "Invalid feed URL" });
|
||||
}
|
||||
const url = new URL(href);
|
||||
|
||||
const cacheKey = `feed:${url.href}`;
|
||||
let items = cache.get(cacheKey);
|
||||
|
||||
@@ -52,6 +52,12 @@ describe("widgets/feed/proxy", () => {
|
||||
await feedProxyHandler(req, res);
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(res.body).toEqual({ error: "Invalid feed URL" });
|
||||
|
||||
getServiceWidget.mockResolvedValueOnce({ type: "feed", url: "file:///etc/passwd" });
|
||||
res = createMockRes();
|
||||
await feedProxyHandler(req, res);
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(res.body).toEqual({ error: "Invalid feed URL" });
|
||||
expect(httpProxy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user