Skip to content

matthewwong525/WongStack / .agents/plugins/access

access

Verified

See who can sign in and what each person may use; add, change or remove a person.

FileKindSize
README.mdmarkdown3.4 KB
SKILL.mdskill md2.3 KB
VERSIONother6 B
hooks/claude.jsonconfig251 B
hooks/codex.jsonconfig232 B
references/setup.mdmarkdown9.7 KB
screen/access.cssother10.5 KB
screen/address.mjsscript2.1 KB
screen/api.mjsscript11.6 KB
screen/api.test.mjsscript13.4 KB
screen/app.mjsscript1.2 KB
screen/app.test.mjsscript40.3 KB
screen/confirm.mjsscript1.1 KB
screen/context.mjsscript248 B
screen/copy-text.mjsscript1.3 KB
screen/fields.mjsscript1001 B
screen/hidden.test.mjsscript6.8 KB
screen/labels.mjsscript1.4 KB
screen/leaving.test.mjsscript14.6 KB
screen/level-choice.mjsscript1.3 KB
screen/levels.mjsscript3.7 KB
screen/levels.test.mjsscript7.9 KB
screen/loading.mjsscript457 B
screen/main.d.mtsother1.0 KB
screen/main.mjsscript1.3 KB
screen/note.mjsscript2.1 KB
screen/note.test.mjsscript4.1 KB
screen/notices.mjsscript4.3 KB
screen/notices.test.mjsscript2.2 KB
screen/own.mjsscript889 B
screen/owner.mjsscript2.7 KB
screen/page.mjsscript4.2 KB
screen/people.mjsscript4.5 KB
screen/person-page.mjsscript3.5 KB
screen/person-page.test.mjsscript37.2 KB
screen/project-step.mjsscript1.7 KB
screen/project-step.test.mjsscript5.4 KB
screen/pushers.mjsscript3.5 KB
screen/pushers.test.mjsscript5.2 KB
screen/role-page.mjsscript2.5 KB
screen/role-select.mjsscript1.6 KB
screen/roles.mjsscript1.5 KB
screen/roles.test.mjsscript22.2 KB
screen/router.mjsscript3.3 KB
screen/seal.d.mtsother470 B
screen/seal.mjsscript2.6 KB
screen/seal.test.mjsscript1.1 KB
screen/services.mjsscript4.3 KB
screen/services.test.mjsscript12.5 KB
screen/set-fields.mjsscript3.5 KB
screen/status.mjsscript2.4 KB
screen/status.test.mjsscript2.7 KB
screen/style.test.mjsscript11.5 KB
screen/subjects.mjsscript487 B
screen/subjects.test.mjsscript2.4 KB
screen/table.mjsscript4.5 KB
screen/test-dom.mjsscript9.4 KB
screen/ui.mjsscript14.2 KB
screen/view.mjsscript2.1 KB
screen/welcome.mjsscript2.3 KB
screen/welcome.test.mjsscript11.2 KB
scripts/check-definitions.mjsexecutablescript1.1 KB
scripts/lib/check-definitions.mjsscript1.2 KB
scripts/lib/client.mjsscript4.6 KB
scripts/lib/openapi.mjsscript20.6 KB
scripts/lib/scrub.mjsscript7.0 KB
scripts/lib/seal-keys.mjsscript1.1 KB
scripts/lib/services.mjsscript17.6 KB
scripts/services.mjsexecutablescript8.6 KB
scripts/session-start.mjsscript1.7 KB
server/errors.d.mtsother572 B
server/errors.mjsscript1.8 KB
server/errors.test.mjsscript1.3 KB
server/forward.d.mtsother1.6 KB
server/forward.mjsscript11.0 KB
server/forward.test.mjsscript9.4 KB
server/index.d.mtsother3.3 KB
server/index.mjsscript11.3 KB
server/index.test.mjsscript11.8 KB
server/key-rules.d.mtsother643 B
server/key-rules.mjsscript4.0 KB
server/key-rules.test.mjsscript5.2 KB
server/levels.d.mtsother2.3 KB
server/levels.mjsscript4.3 KB
server/levels.test.mjsscript2.4 KB
server/management.mjsscript2.8 KB
server/page.mjsscript1.3 KB
server/pass.d.mtsother213 B
server/pass.mjsscript3.5 KB
server/people.mjsscript5.3 KB
server/policy.d.mtsother1.5 KB
server/policy.mjsscript8.1 KB
server/roles.mjsscript2.4 KB
server/sealed.d.mtsother377 B
server/sealed.mjsscript3.2 KB
server/sealed.test.mjsscript4.9 KB
server/services.d.mtsother487 B
server/services.mjsscript3.1 KB
server/services.test.mjsscript4.5 KB
server/sets.mjsscript4.5 KB
server/start.mjsscript1.8 KB
server/tools.d.mtsother1.2 KB
server/tools.mjsscript8.7 KB
server/tools.test.mjsscript10.4 KB
signin/cloudflare-list.d.mtsother969 B
signin/cloudflare-list.mjsscript11.6 KB
signin/cloudflare-list.test.mjsscript1.4 KB
signin/cloudflare.d.mtsother1.5 KB
signin/cloudflare.mjsscript7.2 KB
signin/cloudflare.test.mjsscript1.4 KB
signin/computer.d.mtsother557 B
signin/computer.mjsscript2.4 KB
signin/computer.test.mjsscript1.0 KB
store/contract.d.mtsother293 B
store/contract.mjsscript14.3 KB
store/interface.d.mtsother4.2 KB
store/interface.mjsscript1.2 KB
store/stand-in.d.mtsother93 B
store/stand-in.mjsscript10.4 KB
store/stand-in.test.mjsscript202 B

signin/cloudflare-list.mjs

View on GitHub
// The live app's own sign-in list on Cloudflare Access: exact applications and their human policies only. Its key
// can not run hosting or memory. The project's `signInList` slot is `cloudflareList(config)`.
import { AccessError, Unreadable, boundedJson } from '../server/errors.mjs';
import { isEmail, isObject } from '../server/sets.mjs';

const CF = 'https://api.cloudflare.com/client/v4';
const POLICY_ID = /^[A-Za-z0-9-]+$/;
const ACCOUNT_ID = /^[a-f0-9]{32}$/;
const APP_ID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/;
// Fields Cloudflare owns; everything else in the live policy goes back unchanged.
const READ_ONLY = ['id', 'created_at', 'updated_at', 'uid', 'app_count'];

const exactly = (value, fields, optional = []) => isObject(value) && Object.keys(value).every(name => fields.includes(name) || optional.includes(name)) &&
  fields.every(name => Object.hasOwn(value, name));
const text = value => typeof value === 'string';
const list = value => Array.isArray(value);
/** A value in the shape asked, else Unreadable: an answer this module can not read. */
const read = (value, check) => { if (!check(value)) throw new Unreadable(); return value; };

/** Setup's key for the sign-in list, from its JSON. Version 3 adds the previews app: that list plus GitHub pushers.
 *  Null until setup has supplied it, or when it is not in this shape. */
export function loginAuthority(json) {
  let value;
  try { value = JSON.parse(json ?? ''); } catch { return null; }
  const staging = value?.staging;
  const ok = exactly(value, ['version', 'token', 'accountId', 'policyId'], ['staging']) && [2, 3].includes(value.version) &&
    text(value.token) && value.token.length > 0 && text(value.accountId) && ACCOUNT_ID.test(value.accountId) &&
    text(value.policyId) && POLICY_ID.test(value.policyId) &&
    (staging === undefined || (exactly(staging, ['appId', 'policyId']) && text(staging.appId) && APP_ID.test(staging.appId) &&
      text(staging.policyId) && POLICY_ID.test(staging.policyId))) &&
    (value.version === 3) === (staging !== undefined);
  return ok ? value : null;
}

/** Fixed provider origin only. A redirect comes back unfollowed and fails like any non-2xx answer, so it never
 *  receives the key. */
export async function provider(path, token, method = 'GET', body) {
  if (!path.startsWith('/') || path.startsWith('//') || path.includes('..')) throw new AccessError('provider_destination_invalid');
  const response = await fetch(`${CF}${path}`, { method, redirect: 'manual', signal: AbortSignal.timeout(30_000),
    headers: { ...(token && { Authorization: `Bearer ${token}` }), Accept: 'application/json', 'Content-Type': 'application/json',
      'User-Agent': 'WongStack-employee-access' },
    ...(body && { body: JSON.stringify(body) }) });
  if (!response.ok) throw new AccessError(response.status === 404 ? 'provider_not_found' : 'provider_unavailable');
  if (response.status === 204) return null;
  return boundedJson(response, 1_048_576);
}

const envelope = value => read(value, item => isObject(item) && item.success === true).result;
const emailRule = rule => exactly(rule, ['email']) && exactly(rule.email, ['email']) && isEmail(rule.email.email);
// Cloudflare's app-scoped policy list can leave `session_duration` out: an absent field stays absent on the write.
const isPolicy = value => isObject(value) && text(value.id) && text(value.name) && value.decision === 'allow' &&
  list(value.include) && value.include.every(emailRule) && list(value.exclude) && list(value.require) &&
  (value.session_duration === undefined || text(value.session_duration)) &&
  (value.app_count === undefined || typeof value.app_count === 'number') && (value.reusable === undefined || typeof value.reusable === 'boolean');
const isApp = value => isObject(value) && text(value.id) && text(value.aud) && list(value.destinations) &&
  value.destinations.every(item => isObject(item) && text(item.type) && (item.worker_id === undefined || text(item.worker_id)));
const isListed = value => list(value) && value.every(item => isObject(item) && text(item.id) && text(item.decision) && list(item.include));
const serviceToken = rule => exactly(rule, ['service_token']) && exactly(rule.service_token, ['token_id']) &&
  text(rule.service_token.token_id) && rule.service_token.token_id.length > 0;
const sorted = values => [...values].sort().join('\n');
const emails = policy => policy.include.map(rule => rule.email.email.trim().toLowerCase());
const controls = value => JSON.stringify(Object.fromEntries(Object.entries(value)
  .filter(([field]) => field !== 'include' && !READ_ONLY.includes(field)).sort(([a], [b]) => a.localeCompare(b))));

/** One application and its human policy, read and reviewed. An unreviewed allow or bypass policy must never become
 *  another way in. */
async function review(authority, appId, policyId, owned) {
  const path = `/accounts/${authority.accountId}/access/apps/${appId}`;
  const app = read(envelope(await provider(path, authority.token)), isApp);
  if (app.id !== appId || !owned(app)) throw new AccessError('login_resource_mismatch');
  const policies = read(envelope(await provider(`${path}/policies?per_page=1000`, authority.token)), isListed);
  if (policies.length > 2 || policies.some(policy => policy.id !== policyId &&
    (policy.decision !== 'non_identity' || !policy.include.length || !policy.include.every(serviceToken)))) {
    throw new AccessError('login_policy_review_required');
  }
  const policy = read(policies.find(item => item.id === policyId), isPolicy);
  if (policy.reusable || (policy.app_count !== undefined && policy.app_count !== 1)) throw new AccessError('login_policy_review_required');
  return { path, policy };
}

/** The sign-in list on Cloudflare Access. `config`: `key()` gives setup's key JSON; `appId`, `audience` and
 *  `workerId` name the live app's application; `previews({ store })` gives the emails the previews app adds, such as
 *  GitHub pushers. */
export function cloudflareList(config) {
  const authority = () => loginAuthority(config.key());

  /** The live app's application, then the previews app's once split: each reviewed alike. */
  async function applications(key) {
    const { appId, audience, workerId } = config;
    if (!appId || !audience || !workerId) throw new AccessError('login_resource_mismatch');
    // The live app's application must be this app's own and cover this server.
    const live = await review(key, appId, key.policyId, app => app.aud === audience &&
      app.destinations.some(destination => destination.type === 'worker' && destination.worker_id === workerId));
    if (!key.staging) return [live];
    // The server knows no previews audience or server, so the previews app is judged by its recorded id alone.
    return [live, await review(key, key.staging.appId, key.staging.policyId, () => true)];
  }

  /** Each application's list, live app first: the owner and active people; the previews app adds its own. */
  async function desiredLists(store, owner, count) {
    const [people, previews] = await Promise.all([store.listed(), config.previews?.({ store }) ?? []]);
    const listed = values => [...new Set(values)].sort();
    return Array.from({ length: count }, (_, at) => listed(at === 0 ? [owner, ...people] : [owner, ...people, ...previews]));
  }

  /** Read each live policy, change only its email list, and send the rest back unchanged. */
  async function updatePolicy(key, { store, owner, holder }, live, generation) {
    const desired = await desiredLists(store, owner, live.length);
    const body = (policy, at) => ({ ...Object.fromEntries(Object.entries(policy).filter(([field]) => !READ_ONLY.includes(field))),
      include: desired[at].map(email => ({ email: { email } })) });
    // No call has begun when this refuses, so no write's outcome is unknown.
    const intent = await store.beginWrite({ generation, holder });
    if (!intent) throw new AccessError('provider_lease_expired');
    try {
      for (const [at, { path, policy }] of live.entries()) await provider(`${path}/policies/${policy.id}`, key.token, 'PUT', body(policy, at));
      await store.endWrite(intent, 'completed');
    } catch (error) {
      await store.endWrite(intent, 'unknown');
      throw error;
    }
    const checked = await applications(key);
    if (checked.some(({ policy }, at) => sorted(emails(policy)) !== sorted(desired[at]) || controls(policy) !== controls(live[at].policy))) {
      throw new AccessError('login_policy_readback_pending');
    }
  }

  /** One provider attempt. False means a newer change arrived meanwhile, so go round again. */
  async function attempt(key, options, { generation, scope }) {
    const { store, holder, kind } = options;
    if (!await store.leaseCurrent(holder)) throw new AccessError('provider_lease_expired');
    const live = await applications(key);
    if (kind === 'policy') await updatePolicy(key, options, live, generation);
    else for (const { path } of scope === 'previews' ? live.slice(1) : live) envelope(await provider(`${path}/revoke_tokens`, key.token, 'POST', {}));
    const current = await store.step(kind);
    if (!current || current.generation !== generation || !await store.leaseCurrent(holder)) {
      // Even a later step's earlier success can be undone by this stale write.
      await store.stepStale(kind);
      return false;
    }
    // An earlier write whose outcome is unknown keeps the list unconfirmed until it can no longer land.
    if (kind === 'policy' && await store.unresolvedWrites()) {
      await store.stepUnresolved();
      return true;
    }
    await store.stepDone({ kind, generation, holder,
      outcome: kind === 'policy' ? 'policy_readback_matches' : 'session_revocation_accepted_propagation_unverified' });
    return true;
  }

  return {
    ready: () => authority() !== null,
    /** Whether the previews app has its own list yet: an older single sign-in app has none to widen. */
    split: () => authority()?.version === 3,
    /** Everyone the live app's list admits now, for the first open's import. */
    async admitted() {
      const key = authority();
      if (!key) return [];
      return emails((await applications(key))[0].policy);
    },
    /** One sign-in list step, `policy` or `sessions`, under the caller's lease. Nothing without the key, or before
     *  permissions start: until the first open has listed everyone already admitted, a write could drop a teammate. */
    async reconcile(options) {
      const key = authority();
      const { store, kind } = options;
      if (!key || !(await store.started()).policy) return;
      for (let round = 0; round < 3; round++) {
        const work = await store.step(kind);
        if (!work || work.status === 'ready') return;
        try {
          if (await attempt(key, options, work)) return;
        } catch (error) {
          await store.stepFailed({ kind, generation: work.generation,
            code: error instanceof AccessError ? error.code : 'login_provider_unavailable' });
          return;
        }
      }
    },
    /** Whether the previews app's list differs from the saved people and its own extras: a rerun of setup rewrites it
     *  without them. One read, and none while a list write waits; an unreadable list counts as matching. */
    async drifted({ store, owner }) {
      const key = authority();
      if (!key?.staging || await store.stepWaiting()) return false;
      try {
        const path = `/accounts/${key.accountId}/access/apps/${key.staging.appId}/policies?per_page=1000`;
        const found = read(envelope(await provider(path, key.token)), value => list(value) && value.every(item => isObject(item) && text(item.id)))
          .find(policy => policy.id === key.staging.policyId);
        return sorted(emails(read(found, isPolicy))) !== sorted((await desiredLists(store, owner, 2))[1]);
      } catch { return false; }
    },
  };
}
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall