A new personal env scope (paradigm user: one user's secret for one bot) beats every other scope, reaches only that user's runs of that bot, and is redacted like any secret. Bots take secrets in with request_secret, which puts a [secret-request:ID] card in the chat: the user types the value into a masked input there, never into a message, and the bot is told only the key. Bots show secrets with capture_secret (a task's computer tool that saves a file or a command's output straight to a personal env, then redacts it from the rest of the run) and show_secret (an env by key): both give a [secret:ID] chip whose Reveal and Copy fetch the value on click, for its own user (personal) or a super admin (anything else), logged by key. Values never go into messages, page props, history, Copy chat or logs. Users manage their own secrets on Settings > Secrets; the Environment page lists everyone's, remove only. Deleting a bot or user removes its personal secrets, and SecretsNote tells bots never to ask for or print secrets in chat. Co-Authored-By: Claude Opus 5.5 <[email protected]>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import canRevealEnv from "@/src/utils/rbac/can-reveal-env";
|
|
import AppError from "@/src/utils/app-error";
|
|
import grabCrewRole from "../access/grab-crew-role";
|
|
import grabUserBot from "../bots/grab-user-bot";
|
|
import grabAllEnvs from "../envs/grab-all-envs";
|
|
|
|
type Params = {
|
|
env_id: number | string;
|
|
user_id: number | string;
|
|
};
|
|
|
|
/**
|
|
* An env a secret ref (`[secret:ID]`) names, with whether this viewer may
|
|
* reveal it (`canRevealEnv`). Someone else's personal secret reads as
|
|
* missing: not even its key is shown to anyone else.
|
|
*/
|
|
export default async function grabRevealableEnv({ env_id, user_id }: Params) {
|
|
const env = (await grabAllEnvs()).find((e) => e.id == Number(env_id));
|
|
|
|
if (!env || (env.paradigm == "user" && env.user_id != Number(user_id))) {
|
|
throw new AppError(`That secret isn't yours or no longer exists.`);
|
|
}
|
|
|
|
const role = await grabCrewRole({ user_id });
|
|
const reaches_bot =
|
|
env.paradigm == "user" && env.bot_id ? Boolean((await grabUserBot({ bot_id: env.bot_id, user_id }))?.id) : false;
|
|
|
|
return { env, can_reveal: canRevealEnv({ env, viewer_id: user_id, role, reaches_bot }) };
|
|
}
|