mirror of
https://github.com/upstash/context7.git
synced 2025-12-04 02:50:31 +00:00
CTX7-272: ip address header
This commit is contained in:
parent
294df1d487
commit
ddac8928a6
@ -34,30 +34,7 @@ function encryptClientIp(clientIp: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decryptClientIp(encryptedIp: string): string | null {
|
|
||||||
if (!validateEncryptionKey(ENCRYPTION_KEY)) {
|
|
||||||
console.error("Invalid encryption key format. Cannot decrypt.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const parts = encryptedIp.split(":");
|
|
||||||
if (parts.length !== 2) {
|
|
||||||
// Not encrypted, return as-is
|
|
||||||
return encryptedIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
const iv = Buffer.from(parts[0], "hex");
|
|
||||||
const encrypted = parts[1];
|
|
||||||
const decipher = createDecipheriv(ALGORITHM, Buffer.from(ENCRYPTION_KEY, "hex"), iv);
|
|
||||||
let decrypted = decipher.update(encrypted, "hex", "utf8");
|
|
||||||
decrypted += decipher.final("utf8");
|
|
||||||
return decrypted;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error decrypting client IP:", error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for libraries matching the given query
|
* Searches for libraries matching the given query
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user