Skip to content

Commit 16019ec

Browse files
fix: codeQL
1 parent 1352b62 commit 16019ec

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

graph.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ export async function startGraph() {
164164
res.json({ status: "ok", attestation });
165165
}
166166
catch (error) {
167-
console.error("Error storing offchain attestation:", error);
167+
const sanitizedError = typeof error === "string" ? error.replace(/\n|\r/g, "") : JSON.stringify(error).replace(/\n|\r/g, "");
168+
console.error("Error storing offchain attestation:", sanitizedError);
168169
res.status(500).json({ error: "Internal server error" });
169170
}
170171
});

utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,8 @@ export async function updateDbFromEthTransaction(txId: string) {
839839
}
840840

841841
export async function storeOffchainAttestation(pkg: AttestationShareablePackageObject) {
842-
console.log("Storing offchain attestation", pkg);
842+
const sanitizedPkg = JSON.stringify(pkg).replace(/[\n\r]/g, "");
843+
console.log("Storing offchain attestation", sanitizedPkg);
843844

844845
const config: OffchainConfig = {
845846
address: pkg.sig.domain.verifyingContract,
@@ -851,12 +852,14 @@ export async function updateDbFromEthTransaction(txId: string) {
851852
const isValidAttestation = offchain.verifyOffchainAttestationSignature(pkg.signer, pkg.sig);
852853

853854
if (!isValidAttestation) {
854-
console.log("Invalid offchain attestation signature", pkg.sig);
855+
const sanitizedSig = JSON.stringify(pkg.sig).replace(/\n|\r/g, "");
856+
console.log("Invalid offchain attestation signature", sanitizedSig);
855857
throw new Error("Invalid offchain attestation signature");
856858
}
857859

858-
if (pkg.sig.message.time < dayjs().startOf("day").unix()) {
859-
console.log("Offchain attestation is too old", pkg.sig.message.time);
860+
const sanitizedTime = String(pkg.sig.message.time).replace(/\n|\r/g, "");
861+
if (Number(sanitizedTime) < dayjs().startOf("day").unix()) {
862+
console.log("Offchain attestation is too old", sanitizedTime);
860863
throw new Error("Offchain attestation is too old");
861864
}
862865

0 commit comments

Comments
 (0)