mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 08:13:50 +00:00
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
// How permissions are shown to people: the consent dialog and the plugin list
|
|
// in Settings. The text itself lives in the locale files under
|
|
// `plugins.permissions.<key>.{title,body}`.
|
|
|
|
import { ALL_PERMISSIONS, IMPLICIT_PERMISSIONS } from '../plugin-types';
|
|
|
|
/**
|
|
* Permissions that let a plugin read or send mail content, change what is
|
|
* sent or shown, run with full access, or move data off the device. The
|
|
* consent dialog lists them first and marks them.
|
|
*/
|
|
export const HIGH_RISK_PERMISSIONS: ReadonlySet<string> = new Set([
|
|
'crypto:full',
|
|
// email.get reads any message in the account, not only the open one.
|
|
'email:read',
|
|
'email:send',
|
|
'email:raw-send',
|
|
'email:blob-read',
|
|
'email:blob-write',
|
|
'email:render-takeover',
|
|
'http:fetch',
|
|
'http:post',
|
|
'filters:write',
|
|
'http:proxy',
|
|
// A plugin can point the reply-to of a sender address elsewhere, so
|
|
// answers to the user's mail go to someone else.
|
|
'identity:write',
|
|
// The out-of-office reply goes out to everyone who writes, in the user's
|
|
// name, with whatever text the plugin set.
|
|
'vacation:write',
|
|
]);
|
|
|
|
/** Locale key segment for a permission: `email:read` → `email_read`. */
|
|
export function permissionKey(perm: string): string {
|
|
return perm.replace(/[:-]/g, '_');
|
|
}
|
|
|
|
/** Permissions worth showing: known, not implicit, high-risk first. */
|
|
export function visiblePermissions(perms: readonly string[]): string[] {
|
|
const known = new Set<string>(ALL_PERMISSIONS);
|
|
const implicit = new Set<string>(IMPLICIT_PERMISSIONS);
|
|
return [...new Set(perms)]
|
|
.filter((p) => known.has(p) && !implicit.has(p))
|
|
.sort((a, b) => Number(HIGH_RISK_PERMISSIONS.has(b)) - Number(HIGH_RISK_PERMISSIONS.has(a)));
|
|
}
|