mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 21:00:41 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 192071e4a7 | |||
| fcf7c80daa | |||
| ed9251c014 |
+81
-12
@@ -10,6 +10,7 @@ import {
|
||||
Attachment,
|
||||
PasswordHistory,
|
||||
} from '../types';
|
||||
import { LIMITS } from '../config/limits';
|
||||
import { StorageService } from '../services/storage';
|
||||
import { notifyUserVaultSync } from '../durable/notifications-hub';
|
||||
import { jsonResponse, errorResponse } from '../utils/response';
|
||||
@@ -129,6 +130,16 @@ function optionalEncString(value: unknown): string | null {
|
||||
return isValidEncString(value) ? value.trim() : null;
|
||||
}
|
||||
|
||||
function shouldAcceptCipherKey(value: unknown): boolean {
|
||||
if (LIMITS.compatibility.cipherKeyEncryptionFeatureEnabled) return true;
|
||||
return optionalEncString(value) === null;
|
||||
}
|
||||
|
||||
function normalizeCipherKeyForStorage(value: unknown): string | null {
|
||||
if (!LIMITS.compatibility.cipherKeyEncryptionFeatureEnabled) return null;
|
||||
return optionalEncString(value);
|
||||
}
|
||||
|
||||
function sanitizeEncryptedObject<T extends Record<string, any>>(
|
||||
source: T | null | undefined,
|
||||
encryptedKeys: readonly string[]
|
||||
@@ -161,20 +172,57 @@ export function normalizeCipherLoginForStorage(login: any): any {
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeCipherLoginForCompatibility(login: any): any {
|
||||
export function normalizeCipherLoginForCompatibility(login: any, requiresUriChecksum: boolean = false): any {
|
||||
const normalized = normalizeCipherLoginForStorage(login);
|
||||
if (!normalized || typeof normalized !== 'object') return normalized ?? null;
|
||||
const next = sanitizeEncryptedObject(normalized, ['username', 'password', 'totp', 'uri']);
|
||||
if (!next) return null;
|
||||
next.uris = Array.isArray(next.uris)
|
||||
? next.uris
|
||||
.map((uri: any) => sanitizeEncryptedObject(uri, ['uri', 'uriChecksum']))
|
||||
.filter((uri: any) => !!uri && (uri.uri || uri.uriChecksum || uri.match != null))
|
||||
: null;
|
||||
next.uris = normalizeCipherLoginUrisForCompatibility(next.uris, {
|
||||
hasLegacyLoginUri: isValidEncString(next.uri),
|
||||
requiresUriChecksum,
|
||||
});
|
||||
next.fido2Credentials = normalizeFido2CredentialsForCompatibility(next.fido2Credentials);
|
||||
return next;
|
||||
}
|
||||
|
||||
function normalizeCipherLoginUrisForCompatibility(
|
||||
uris: any,
|
||||
options: { hasLegacyLoginUri?: boolean; requiresUriChecksum?: boolean } = {}
|
||||
): any[] | null {
|
||||
if (!Array.isArray(uris) || uris.length === 0) return null;
|
||||
const out: any[] = [];
|
||||
|
||||
for (const uri of uris) {
|
||||
if (!uri || typeof uri !== 'object') continue;
|
||||
const next = sanitizeEncryptedObject(uri, ['uri', 'uriChecksum']);
|
||||
if (!next) continue;
|
||||
|
||||
const hasUri = isValidEncString(next.uri);
|
||||
const hasChecksum = isValidEncString(next.uriChecksum);
|
||||
const hasMatch = next.match != null;
|
||||
|
||||
if (hasUri && hasChecksum) {
|
||||
out.push(next);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasUri && !hasChecksum) {
|
||||
// Bitwarden browser clients using the SDK can fail the whole vault load
|
||||
// when an item-key encrypted URI has no encrypted checksum. The server
|
||||
// cannot derive the checksum, so expose the item without the bad URI.
|
||||
if (options.requiresUriChecksum || options.hasLegacyLoginUri) continue;
|
||||
out.push({ ...next, uri: null, uriChecksum: null });
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasChecksum || hasMatch) {
|
||||
out.push(next);
|
||||
}
|
||||
}
|
||||
|
||||
return out.length ? out : null;
|
||||
}
|
||||
|
||||
function hasMissingLoginUriChecksum(cipher: Cipher): boolean {
|
||||
if (!cipher.key || !cipher.login || typeof cipher.login !== 'object') return false;
|
||||
const uris = (cipher.login as any).uris;
|
||||
@@ -255,6 +303,14 @@ export function normalizeCipherSshKeyForCompatibility(sshKey: any): any {
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeCipherSecureNoteForCompatibility(secureNote: any): CipherSecureNote | null {
|
||||
if (!secureNote || typeof secureNote !== 'object') return null;
|
||||
const type = Number(secureNote?.type ?? secureNote?.Type ?? 0);
|
||||
return {
|
||||
type: Number.isFinite(type) ? type : 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Format attachments for API response
|
||||
export function formatAttachments(attachments: Attachment[]): any[] | null {
|
||||
if (attachments.length === 0) return null;
|
||||
@@ -506,7 +562,10 @@ export function cipherToResponse(
|
||||
): CipherResponse {
|
||||
// Strip internal-only fields that must not appear in the API response
|
||||
const { userId, createdAt, updatedAt, archivedAt, deletedAt, ...passthrough } = cipher;
|
||||
const normalizedLogin = normalizeCipherLoginForCompatibility((passthrough as any).login ?? null);
|
||||
const responseCipherKey = LIMITS.compatibility.cipherKeyEncryptionFeatureEnabled
|
||||
? optionalEncString(cipher.key)
|
||||
: null;
|
||||
const normalizedLogin = normalizeCipherLoginForCompatibility((passthrough as any).login ?? null, !!responseCipherKey);
|
||||
const normalizedCard = sanitizeEncryptedObject((passthrough as any).card ?? null, ['cardholderName', 'brand', 'number', 'expMonth', 'expYear', 'code']);
|
||||
const normalizedIdentity = sanitizeEncryptedObject((passthrough as any).identity ?? null, [
|
||||
'title',
|
||||
@@ -529,6 +588,9 @@ export function cipherToResponse(
|
||||
'licenseNumber',
|
||||
]);
|
||||
const normalizedSshKey = normalizeCipherSshKeyForCompatibility((passthrough as any).sshKey ?? null);
|
||||
const normalizedSecureNote = Number(cipher.type) === 2
|
||||
? normalizeCipherSecureNoteForCompatibility((passthrough as any).secureNote ?? null) ?? { type: 0 }
|
||||
: null;
|
||||
const responseAttachments = applyCipherEmbeddedAttachmentMetadata(cipher, attachments);
|
||||
|
||||
return {
|
||||
@@ -557,10 +619,11 @@ export function cipherToResponse(
|
||||
login: normalizedLogin,
|
||||
card: normalizedCard,
|
||||
identity: normalizedIdentity,
|
||||
secureNote: normalizedSecureNote,
|
||||
fields: normalizeCipherFieldsForCompatibility((passthrough as any).fields),
|
||||
passwordHistory: normalizePasswordHistoryForCompatibility((passthrough as any).passwordHistory),
|
||||
sshKey: normalizedSshKey,
|
||||
key: optionalEncString(cipher.key),
|
||||
key: responseCipherKey,
|
||||
encryptedFor: (passthrough as any).encryptedFor ?? null,
|
||||
};
|
||||
}
|
||||
@@ -653,6 +716,10 @@ export async function handleCreateCipher(request: Request, env: Env, userId: str
|
||||
const createSshKey = readCipherProp<CipherSshKey | null>(cipherData, ['sshKey', 'SshKey']);
|
||||
const createPasswordHistory = readCipherProp<PasswordHistory[] | null>(cipherData, ['passwordHistory', 'PasswordHistory']);
|
||||
|
||||
if (createKey.present && !shouldAcceptCipherKey(createKey.value)) {
|
||||
return errorResponse('Cipher key encryption is not supported by this server. Resync the client and try again.', 400);
|
||||
}
|
||||
|
||||
const now = new Date().toISOString();
|
||||
// Opaque passthrough: spread ALL client fields to preserve unknown/future ones,
|
||||
// then override only server-controlled fields.
|
||||
@@ -670,7 +737,7 @@ export async function handleCreateCipher(request: Request, env: Env, userId: str
|
||||
deletedAt: null,
|
||||
};
|
||||
cipher.folderId = createFolderId.present ? normalizeOptionalId(createFolderId.value) : normalizeOptionalId(cipher.folderId);
|
||||
cipher.key = createKey.present ? (createKey.value ?? null) : (cipher.key ?? null);
|
||||
cipher.key = normalizeCipherKeyForStorage(createKey.present ? createKey.value : cipher.key);
|
||||
cipher.login = createLogin.present ? (createLogin.value ?? null) : (cipher.login ?? null);
|
||||
cipher.card = createCard.present ? (createCard.value ?? null) : (cipher.card ?? null);
|
||||
cipher.identity = createIdentity.present ? (createIdentity.value ?? null) : (cipher.identity ?? null);
|
||||
@@ -731,6 +798,10 @@ export async function handleUpdateCipher(request: Request, env: Env, userId: str
|
||||
const incomingRevisionDate = readCipherRevisionDate(cipherData);
|
||||
const hasAttachmentMigrationMetadata = hasIncomingAttachmentMetadata(cipherData);
|
||||
|
||||
if (incomingKey.present && !shouldAcceptCipherKey(incomingKey.value)) {
|
||||
return errorResponse('Cipher key encryption is not supported by this server. Resync the client and try again.', 400);
|
||||
}
|
||||
|
||||
if (!hasAttachmentMigrationMetadata && isStaleCipherUpdate(existingCipher.updatedAt, incomingRevisionDate)) {
|
||||
return errorResponse('The client copy of this cipher is out of date. Resync the client and try again.', 400);
|
||||
}
|
||||
@@ -756,9 +827,7 @@ export async function handleUpdateCipher(request: Request, env: Env, userId: str
|
||||
if (incomingFolderId.present) {
|
||||
cipher.folderId = normalizeOptionalId(incomingFolderId.value);
|
||||
}
|
||||
if (incomingKey.present) {
|
||||
cipher.key = incomingKey.value ?? null;
|
||||
}
|
||||
cipher.key = normalizeCipherKeyForStorage(incomingKey.present ? incomingKey.value : existingCipher.key);
|
||||
cipher.login = nextType === 1 ? (incomingLogin.present ? (incomingLogin.value ?? null) : (existingCipher.login ?? null)) : null;
|
||||
cipher.secureNote = nextType === 2 ? (incomingSecureNote.present ? (incomingSecureNote.value ?? null) : (existingCipher.secureNote ?? null)) : null;
|
||||
cipher.card = nextType === 3 ? (incomingCard.present ? (incomingCard.value ?? null) : (existingCipher.card ?? null)) : null;
|
||||
|
||||
@@ -11,14 +11,15 @@
|
||||
}
|
||||
|
||||
.input {
|
||||
@apply h-12 w-full rounded-xl border px-3.5 py-2.5 text-base text-ink outline-none transition;
|
||||
@apply h-12 w-full rounded-xl border px-3.5 py-2.5 text-base leading-normal text-ink outline-none transition;
|
||||
background: var(--panel);
|
||||
border-color: rgba(74, 103, 150, 0.34);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82);
|
||||
}
|
||||
|
||||
select.input {
|
||||
@apply pr-[42px];
|
||||
@apply py-0 pr-[42px];
|
||||
line-height: 1.5;
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
|
||||
@@ -898,6 +898,8 @@
|
||||
}
|
||||
|
||||
.settings-module select.input {
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
padding-right: 30px;
|
||||
background-position:
|
||||
calc(100% - 15px) calc(50% - 3px),
|
||||
|
||||
Reference in New Issue
Block a user