feedkeeper 0.36.6 → 0.36.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/server/dist/api/auth.js
CHANGED
|
@@ -83,9 +83,13 @@ authRouter.get("/me/avatar", requireSession, (req, res) => {
|
|
|
83
83
|
res.type(avatar.mime_type).send(avatar.data);
|
|
84
84
|
});
|
|
85
85
|
authRouter.put("/me/avatar", requireSession, express.raw({ type: ["image/jpeg", "image/png", "image/webp"], limit: AVATAR_MAX_BYTES }), (req, res) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
if (typeof req.body === "string" || Array.isArray(req.body) || !Buffer.isBuffer(req.body)) {
|
|
87
|
+
res.status(400).json({ error: "invalid_image" });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const data = req.body;
|
|
91
|
+
const mimeType = detectAvatarType(data);
|
|
92
|
+
if (!mimeType) {
|
|
89
93
|
res.status(400).json({ error: "invalid_image" });
|
|
90
94
|
return;
|
|
91
95
|
}
|
|
@@ -159,9 +159,13 @@ v1Router.get("/me/avatar", (req, res) => {
|
|
|
159
159
|
});
|
|
160
160
|
// The type is taken from the file signature, never from the declared content type.
|
|
161
161
|
v1Router.put("/me/avatar", express.raw({ type: ["image/jpeg", "image/png", "image/webp"], limit: AVATAR_MAX_BYTES }), (req, res) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
if (typeof req.body === "string" || Array.isArray(req.body) || !Buffer.isBuffer(req.body)) {
|
|
163
|
+
res.status(400).json({ error: "invalid_image" });
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const data = req.body;
|
|
167
|
+
const mimeType = detectAvatarType(data);
|
|
168
|
+
if (!mimeType) {
|
|
165
169
|
res.status(400).json({ error: "invalid_image" });
|
|
166
170
|
return;
|
|
167
171
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const AVATAR_MAX_BYTES = 512 * 1024;
|
|
2
2
|
/** Identify an uploaded image by its signature instead of trusting the declared type. */
|
|
3
3
|
export function detectAvatarType(data) {
|
|
4
|
-
if (!data || (!Buffer.isBuffer(data) && !(data instanceof Uint8Array)))
|
|
4
|
+
if (typeof data === "string" || Array.isArray(data) || !data || (!Buffer.isBuffer(data) && !(data instanceof Uint8Array)))
|
|
5
5
|
return null;
|
|
6
6
|
if (data.length >= 3 && data[0] === 0xff && data[1] === 0xd8 && data[2] === 0xff)
|
|
7
7
|
return "image/jpeg";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes } from "node:crypto";
|
|
2
2
|
import { TOTP, Secret } from "otpauth";
|
|
3
3
|
import { db } from "../db/index.js";
|
|
4
4
|
import { config } from "../config.js";
|
|
5
5
|
export const opaque = () => randomBytes(32).toString("base64url");
|
|
6
|
-
const tokenDigest = (text) =>
|
|
6
|
+
const tokenDigest = (text) => createHmac("sha256", config.sessionSecret).update(text).digest("hex");
|
|
7
7
|
const encryptionKey = () => createHash("sha256").update(`feedkeeper-totp:${config.sessionSecret}`).digest();
|
|
8
8
|
export function seal(text) {
|
|
9
9
|
const iv = randomBytes(12);
|
|
@@ -54,19 +54,19 @@ function resolveLazyImages(doc) {
|
|
|
54
54
|
img.getAttribute("data-actualsrc");
|
|
55
55
|
const src = img.getAttribute("src");
|
|
56
56
|
if (isSafeSource(lazySrc) && (!src || src.startsWith("data:") || src.length < 10 || SCRIPT_IMAGE_SOURCE.test(src))) {
|
|
57
|
-
img.setAttribute("src", lazySrc.trim());
|
|
57
|
+
img.setAttribute("src", encodeURI(lazySrc.trim()));
|
|
58
58
|
}
|
|
59
59
|
const lazySrcset = img.getAttribute("data-lazy-srcset") || img.getAttribute("data-srcset");
|
|
60
60
|
const srcset = img.getAttribute("srcset");
|
|
61
61
|
if (isSafeSource(lazySrcset) && (!srcset || srcset.startsWith("data:"))) {
|
|
62
|
-
img.setAttribute("srcset", lazySrcset.trim());
|
|
62
|
+
img.setAttribute("srcset", encodeURI(lazySrcset.trim()));
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
const sources = doc.querySelectorAll("source");
|
|
66
66
|
for (const source of sources) {
|
|
67
67
|
const lazySrcset = source.getAttribute("data-lazy-srcset") || source.getAttribute("data-srcset");
|
|
68
68
|
if (isSafeSource(lazySrcset)) {
|
|
69
|
-
source.setAttribute("srcset", lazySrcset.trim());
|
|
69
|
+
source.setAttribute("srcset", encodeURI(lazySrcset.trim()));
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|