41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
// P17 HR-Hub core (AK-P17a) — reveal ONE secret field of ONE entry. Resource
|
|
// route (action only): POST { entryId, field } -> { value }. Every reveal is
|
|
// access-checked + audited in the service BEFORE the value is returned. The UI
|
|
// copies the value and clears the clipboard after 30s (PASSWORD_SAFE_COPY_AUTO_
|
|
// CLEAR_MS). Until the AD-8 envelope ticket lands the decrypt step surfaces the
|
|
// M002 "encryption not provisioned" Klartext (crypto seam deferred).
|
|
|
|
import { type ActionFunctionArgs } from "react-router";
|
|
import { badRequestResponse, hrActionErrorResponse, loadHrContext, notFoundResponse, requireHrPermission } from "~/utils/integrations/hrAccess.server";
|
|
import { revealEntryValue, type PasswordSafeSecretField } from "~/utils/integrations/hrPasswordSafeService.server";
|
|
|
|
const SECRET_FIELDS: ReadonlySet<string> = new Set<PasswordSafeSecretField>(["username", "password", "notes"]);
|
|
|
|
export const action = async ({ request, params }: ActionFunctionArgs) => {
|
|
const ctx = await loadHrContext({ request, params, requireModule: true });
|
|
requireHrPermission(ctx, "hr.passwordsafe.use");
|
|
const vaultId = params.vaultId ?? "";
|
|
const form = await request.formData();
|
|
const entryId = form.get("entryId")?.toString() ?? "";
|
|
const field = form.get("field")?.toString() ?? "";
|
|
|
|
if (!entryId || !SECRET_FIELDS.has(field)) {
|
|
throw badRequestResponse();
|
|
}
|
|
|
|
try {
|
|
const value = await revealEntryValue({ tenantId: ctx.tenantId, vaultId, entryId, userId: ctx.userId, field: field as PasswordSafeSecretField });
|
|
return Response.json({ ok: true, value });
|
|
} catch (error) {
|
|
if (error instanceof Response) {
|
|
throw error;
|
|
}
|
|
return hrActionErrorResponse(error);
|
|
}
|
|
};
|
|
|
|
// A direct GET on the reveal endpoint is meaningless and must never leak a value.
|
|
export const loader = () => {
|
|
throw notFoundResponse();
|
|
};
|