Skip to content

feat(cli): review and apply saved SECURITY.md drafts - #489

Open
mldangelo-oai wants to merge 71 commits into
mdangelo/codex/security-policy-draftsfrom
mdangelo/codex/security-policy-command
Open

feat(cli): review and apply saved SECURITY.md drafts#489
mldangelo-oai wants to merge 71 commits into
mdangelo/codex/security-policy-draftsfrom
mdangelo/codex/security-policy-command

Conversation

@mldangelo-oai

@mldangelo-oai mldangelo-oai commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add offline review and explicit application of saved SECURITY.md drafts. policy --apply <artifact-directory> validates the selected repository and component, previews the exact diff, and asks before writing. --write applies an already-reviewed saved draft without another prompt; it cannot write an unseen model response.

This PR remains stacked on #536 and includes its updated head 419e604 and main fd98a90.

Changes

  • Export saved-draft loading and application APIs, with CLI help, documentation and installed-package coverage.
  • Revalidate source checkpoints, inherited policies and aliases before and after application. Keep distinct recovery-required and written-but-unverified outcomes.
  • Preserve existing Unix and Windows security metadata, no-clobber installation, original recovery inodes and concurrent-writer checks.
  • Consolidate duplicate installation and rollback handling while retaining platform-specific permission verification and existing-policy atomic move operations. The first cleanup removed 59 net lines; final reconciliation adds a focused inode regression and removes three more production lines.
  • Create new policies with an exclusive copy under their final filename, addressing filename-specific SELinux transitions without adding a labeling subsystem. Existing-policy metadata preservation and recovery are unchanged. This follows the kernel's filename-based context selection and Node's destination-file creation.
  • Move the long-running policy tests to an existing lighter Windows shard. Keep all seven shards, existing timeouts and exactly-once file coverage.
  • Inherit the parent's canonical Python and native Windows permission fixtures, and its separate scan/policy sandbox checks. Use an awaited asynchronous Bash subprocess for the release-note fixture that previously returned a null Windows child status.

Testing

  • Initial merged policy/API/CLI/configuration run: 199 passed, 14 skipped.
  • Focused installation and recovery regressions after simplification: 14 passed, 3 Windows skips.
  • Final affected policy, CLI, API, runtime, configuration, release and package-layout suites: 784 passed, 28 skipped, 0 failed across nine files.
  • New-file inode regression: failed before the fix, passed afterward. Five focused copy, collision, cleanup, cancellation and retry checks, plus the CLI post-write interrupt regression, passed.
  • Both native macOS scan and policy permission checks passed outside the outer test sandbox.
  • pnpm run types, pnpm run format, pnpm run build, and git diff --check: passed.
  • Windows shard-routing probe: all 100 ordinary test files assigned exactly once across seven shards; policy tests assigned to shard 4. This does not execute Windows tests.
  • Static npm artifact check and installed-package smoke: passed, including public imports, NodeNext types, offline draft preview/apply/recovery, credential locking and bundled runtime checks.
  • Actual plugin cache upgrade from 0.1.59 to main-identical 0.1.60: all 118 installed files match and synthetic credentials remain intact.

The full repository suite was not rerun. Native Windows, SELinux and Docker validation were not performed locally. Current-head CI is left for a second pass.

  • Final main refresh (fd98a90): package 0.1.21 includes the MCP launcher-permission fix; feature source and bundled payload are unchanged. Types/model generation, formatting, build, 28 focused tests, static artifact verification and full installed-package smoke passed, including MCP initialization. CI was not awaited.

Risk and rollout

Applying a draft replaces only the selected policy after explicit approval. It does not stage, commit or publish it. Retain reported recovery files until concurrent editor writes are reconciled. Filesystem generation checks do not make the final observation and following move one atomic operation.

New-policy installation creates the final inode exclusively, but does not promise atomic visibility of the copied contents. Existing collision, partial-write and written-but-unverified handling remains covered. Native SELinux confirmation is still needed; local inode tests and the upstream implementation support the fix but do not replace kernel integration testing. The release-note fixture and shard changes still need native Windows confirmation, including timing. Do not treat this pass as merge approval.

Public disclosure review

  • No customer, partner, prospect, or user identities, data, or identifying details are included.
  • No credentials, personal data, private source, scan findings, or nonpublic links or tickets are included.
  • I reviewed the branch name, title, description, commits, changes, comments, logs, screenshots, attachments, and links for public disclosure.

Preexisting public history includes contributor metadata and requester-only automated review links. Those links are not reproduced here; the second attestation remains unchecked. New examples and tests are synthetic.

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current head, b1de4d9394c8c8ef7a155d0246735405186c9a11.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: b1de4d9394

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: b1de4d9394

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread sdk/typescript/src/security-policy.ts

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current head, 5c0acd8.

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review
@codex security review

Please review exact head 95f168ba41e01fc13534285296585a07c7d8ba52, including complete Windows audit control flags and mandatory integrity labels, preserving Unix owners, groups, special permissions, and access-control entries, and revalidating retained recovery evidence when retrying an installed policy.

Real Unix permission-metadata and verification-retry regressions failed on the preceding head and now pass. Local TypeScript, formatting, and combined policy, CLI, API, and configuration checks passed; exact-head native Windows and macOS checks are pending.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95f168ba41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/typescript/src/security-policy.ts
Comment thread sdk/typescript/src/security-policy.ts Outdated
Comment thread sdk/typescript/src/security-policy.ts Outdated
Comment thread sdk/typescript/src/security-policy.ts Outdated
@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review
@codex security review

Please review exact head a47da34698991972ac7287530215199d23be4e17, including permission-preserving atomic Unix installation and rollback without hard links, safe cross-filesystem recovery retries, recovery-content revalidation, validated snapshot state, and preserving installed-policy error classification.

Real read-only and rollback access-control regressions, cross-filesystem recovery, retry races, existing alias verification, and atomic concurrent-writer protections pass locally. Exact-head native Windows and macOS checks are pending.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a47da34698

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/typescript/src/security-policy.ts Outdated
Comment thread sdk/typescript/src/security-policy.ts Outdated
@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review
@codex security review

Please review the exact current head afbdd0e8ffa9b74521a0266e17c75b1859fbef10, including Linux security-context preservation, stable recovery snapshots, cross-platform security metadata, unchanged-draft validation, and policy installation/recovery races.

Local validation: 196 tests passed, 11 platform-specific tests skipped, and no tests failed. Fresh Linux, macOS, and Windows CI is running.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: afbdd0e8ff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/typescript/src/security-policy.ts
@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review
@codex security review

Please review exact current head 5a1ed9c1c805ca51665083f9ea6d41a5985426de, including complete ordered Windows system access-control entries, resource and scoped-policy categories, mandatory integrity labels, Linux security contexts, stable recovery snapshots, and cross-platform installation/recovery races.

Local validation: 196 tests passed, 12 platform-specific tests skipped, and no tests failed. Fresh native Windows, Linux, and macOS CI is running.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a1ed9c1c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/typescript/src/security-policy.ts
Comment on lines +1235 to +1238
const temporary = join(
dirname(target.targetPath),
`.SECURITY.md.${randomUUID()}.tmp`,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the target SELinux label when creating a policy

On SELinux systems with a filename-specific type transition for SECURITY.md, creating the inode under this randomized .tmp name gives it the temporary file's context, and the later hard-link or rename does not recompute the label for the final name. Because the new-policy path has no metadata reference, post-write verification never notices that the installed policy has the wrong mandatory-access context. The earlier existing-policy context preservation does not cover this branch; create or relabel the inode using the target's expected context and verify it after installation.

AGENTS.md reference: sdk/typescript/AGENTS.md:L27-L27

Useful? React with 👍 / 👎.

@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review
@codex security review

Please review exact current head 8f061f012d56d4e1b21452481dfb9dc9499394af, particularly the new stable Windows rollback snapshot verification, complete system access-control entries, resource attributes, mandatory integrity labels, existing Linux security contexts, and cross-platform installation/recovery races.

The separate open review item concerning filename-specific SELinux context transitions for a brand-new policy remains unresolved and is intentionally not changed by this Windows-only update.

Local validation: 196 tests passed, 13 platform-specific tests skipped, and no tests failed. Fresh native Windows, Linux, and macOS CI is running.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f061f012d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/typescript/src/security-policy.ts Outdated
Comment thread sdk/typescript/src/security-policy.ts
Comment thread sdk/typescript/src/security-policy.ts
@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review
@codex security review

Please review exact current head bfac0391e2d2e851ccd7087b921a18cdf90c3279, including complete raw discretionary/system ACL bytes and control flags, stable Windows recovery snapshots after descriptor verification, reviewed installed-content rechecks, resource attributes, mandatory integrity labels, and cross-platform recovery races.

The separate open review item concerning filename-specific SELinux context transitions for a brand-new policy remains unresolved and is intentionally not changed by this update.

Local validation: 197 tests passed, 14 platform-specific tests skipped, and no tests failed. Fresh native Windows, Linux, and macOS CI is running.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfac0391e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/typescript/src/security-policy.ts
@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review
@codex security review

Please review exact current head d9b4f0678b7753874376b9896ec8744698409921, including late out-of-scope policy aliases after permission verification, complete discretionary/system ACL bytes and control flags, stable recovery snapshots, reviewed installed-content rechecks, resource attributes, mandatory integrity labels, and cross-platform recovery races.

The separate open review item concerning filename-specific SELinux context transitions for a brand-new policy remains unresolved and is intentionally not changed by this update.

Local validation: 198 tests passed, 14 platform-specific tests skipped, and no tests failed. Fresh native Windows, Linux, and macOS CI is running.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9b4f0678b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/typescript/src/security-policy.ts Outdated
Comment thread sdk/typescript/src/security-policy.ts
@mldangelo-oai

Copy link
Copy Markdown
Collaborator Author

@codex review
@codex security review

Please review exact current head 645bd253eadd71d9c4dbfae14069604380b0d920, including independent Unix and Windows recovery change-generation checks, complete discretionary/system ACL bytes and control flags, open-writer metadata and content races, late out-of-scope policy aliases, resource attributes, and mandatory integrity labels.

The separate open review item concerning filename-specific SELinux context transitions for a brand-new policy remains unresolved and is intentionally not changed by this update. Filesystem change-generation checks do not make their final observation and the following operating-system move one atomic operation.

Local validation: 199 tests passed, 14 platform-specific tests skipped, and no tests failed. Fresh native Windows, Linux, and macOS CI is running.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 645bd253ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 255925c081

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1393 to +1394
await validatePolicyLinks(target);
if ((await readSecurityPolicy(target.targetPath)) !== draft.content) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recheck inherited policies after permission verification

When applying an existing component policy, an editor or checkout operation can change a regular ancestor SECURITY.md while the potentially slow Unix metadata or Windows descriptor verification runs. This final block revalidates aliases and the installed target only, so the changed inherited-policy hash is never checked again and the operation can report written or unchanged against guidance different from the reviewed snapshot. Repeat the inherited snapshot check after permission verification before returning success.

AGENTS.md reference: sdk/typescript/AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

Comment on lines +1328 to +1330
} finally {
// Preserve the write or recovery outcome if temporary cleanup fails.
await rm(temporary, { force: true }).catch(() => undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fail verification when the staging hard link remains

When a writable new policy—or a writable existing policy on Windows—is installed through the hard-link path and removing the staging name fails, this suppression still lets application report success. The leftover .SECURITY.md.*.tmp is another name for the installed inode, so a later write through that unreported path changes the reviewed policy after all verification has passed. Treat this cleanup failure as a written-but-unverified result, or ensure installation cannot leave an unverified hard-link alias.

AGENTS.md reference: sdk/typescript/AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4014d9fe0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +243 to +247
(changed &&
interactive &&
(await prompt.confirm(
`Write this policy to ${display(draft.targetPath)}?`,
false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Align the default write prompt with the README

When policy . runs in an interactive terminal and the generated draft differs, this new branch can apply it immediately after confirmation, while the top-level README still promises that the default command drafts a policy “without changing the checkout” and presents --apply as the separate writing workflow. Either retain the advertised draft-only default or update the public workflow documentation to state that ordinary interactive generation may write SECURITY.md.

AGENTS.md reference: AGENTS.md:L40-L41

Useful? React with 👍 / 👎.

Comment on lines +1462 to +1464
// Create the inode under its final name for filename-based SELinux labels.
// A separate inode also keeps Windows temp cleanup from changing its mode.
await copyFile(temporary, targetPath, constants.COPYFILE_EXCL);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep new-policy publication atomic

When creating a previously absent policy, copyFile creates the final SECURITY.md before all bytes have been copied, so a concurrent scan can read and enforce a truncated policy; an abrupt process termination can also leave that partial file behind without reaching the catch path that reports written_unverified. Publish a fully populated inode atomically while separately applying or verifying the final-path SELinux context.

AGENTS.md reference: sdk/typescript/AGENTS.md:L22-L23

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants