mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-05 16:10:43 +00:00
Co-authored-by: sai nikhil kethe <nikhil@openobserve.ai> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
// Copyright 2026 OpenObserve Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/** Hash of "email:org" (djb2 without crypto.subtle); an org-only key leaks one user's data to the next login. */
|
|
export const computeUserOrgKey = async (
|
|
userEmail: string,
|
|
orgIdentifier: string,
|
|
): Promise<string> => {
|
|
const raw = `${userEmail}:${orgIdentifier}`;
|
|
|
|
if (typeof crypto !== "undefined" && crypto.subtle) {
|
|
const buf = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(raw));
|
|
return Array.from(new Uint8Array(buf))
|
|
.map((b) => b.toString(16).padStart(2, "0"))
|
|
.join("");
|
|
}
|
|
|
|
// Synchronous djb2 fallback (test environments without crypto.subtle)
|
|
let hash = 5381;
|
|
for (let i = 0; i < raw.length; i++) {
|
|
hash = (((hash << 5) + hash) ^ raw.charCodeAt(i)) >>> 0;
|
|
}
|
|
return hash.toString(36);
|
|
};
|