Skip to content

A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.

Add secure coding requirements (#381)

Priyanshu Agrawalbce09d266c12
diff --git a/plugins/power-pages/AGENTS.md b/plugins/power-pages/AGENTS.md
index 9be05f207..5fbf766f2 100644
--- a/plugins/power-pages/AGENTS.md
+++ b/plugins/power-pages/AGENTS.md
@@ -412,6 +412,23 @@ These patterns have caused repeated PR review feedback. Check for them before su
- **Template placeholders in `<script>` blocks need special care** — `render-template.js` injects string values as-is (no encoding), which is safe for HTML text contexts but risky inside JavaScript. Avoid declaring JS variables with `"__PLACEHOLDER__"` in script blocks; prefer reading from the DOM or using `JSON.stringify` for JS contexts.
- **Guidance must be consistent within a skill** — If one section says "always use raw fetch", a framework-specific table in the same file must not recommend a different HTTP client without qualification. Reviewers will flag contradictions.
+## Secure Coding Requirements
+
+These requirements apply to scripts, hooks, skills, templates, reports, and documentation.
+
+- **Process execution:** Non-constant data from users, files, environment variables, APIs, or CLI output MUST NEVER reach `exec`/`execSync` command strings or a child process launched with `shell: true`. New and changed calls MUST use `execFile`, `execFileSync`, `spawn`, or `spawnSync` with a fixed executable, an argv array, and `shell: false`; follow the argv patterns in `scripts/lib/pac-bap-shim.js` and `scripts/lib/telemetry/lib/pac-auth.js` instead of adding quoting helpers.
+- **Authenticated URL boundary:** Introduce one authenticated-URL validator in `scripts/lib/validation-helpers.js`, then require every caller to reuse it before `getAuthToken`, an `Authorization` header, or any authenticated request is created. The validator MUST require HTTPS, reject credentials and unexpected ports, and match the parsed hostname against the Microsoft cloud mappings in `CLOUD_TO_API` and the approved Dataverse host suffixes; validate redirects and `@odata.nextLink` values again, and NEVER use substring host checks or local one-off regexes.
+- **Untrusted report data:** Keep report data as data. Prefer DOM `textContent`; otherwise use the encoder for the exact HTML text, HTML attribute, JavaScript string, or URL component context, and NEVER put raw values into `innerHTML`, event-handler attributes, script source, or navigation URLs. Reuse or extend the encoding boundary in `scripts/lib/render-template.js` and `scripts/lib/templates/security-review-report.html` rather than adding per-report escaping.
+- **Script embedding:** Every value embedded in `<script>`, including strings, MUST pass through `JSON.stringify`; escape characters that can terminate or alter the script context after serialization. The non-string branch in `scripts/lib/render-template.js` shows part of this pattern but is not a complete encoder for string placeholders. Quoted `__PLACEHOLDER__` substitution is not JSON-safe. Treat filenames, labels, findings, and scanner output as untrusted even when the plugin produced the file.
+- **Plugin code resolution:** Resolve plugin-owned code from `__dirname` or the host-provided `${PLUGIN_ROOT}` / `${CLAUDE_PLUGIN_ROOT}` and fail closed when neither is available. `process.cwd()` is a project-input location only and MUST NEVER be a fallback for locating plugin scripts, hooks, templates, configuration, or dependencies.
+- **Runtime dependencies:** Runtime packages MUST use an exact version and a committed lock or equivalent integrity record at the owning package boundary. NEVER fetch and execute `@latest`, an unpinned package, or installer output during a plugin run; this includes MCP launchers such as `scripts/launch-playwright-mcp.js`.
+- **Archives:** Treat archive entry names and metadata as hostile before listing or extraction. Upgrade existing solution-archive entry points, including `skills/export-solution/scripts/validate-export.js`, to use a shell-free library or fixed executable plus argv, inspect entries first, enforce file/count/size limits, reject absolute paths, traversal, links, and special files, and extract only into a new private temporary directory.
+- **Approval guardrails:** `references/approval-gates.md` and `scripts/lint-skills-alm.js` are the source of truth for plugin Approval Gates, and host tool approvals MUST remain enabled. Documentation and skills MAY recommend narrow command allowlists, but MUST NEVER recommend global permission bypasses or options such as `--dangerously-skip-permissions`.
+- **Telemetry and privacy:** Follow the `## Telemetry` contract below and minimize every event to its allowlisted operational fields; NEVER collect prompts, report contents, secrets, tokens, full paths, URLs, hostnames, tenant data, or user content. Disclosures MUST accurately state the shipped default, local mirror behavior, and opt-out precedence; telemetry-capable CI jobs MUST set `POWER_PLATFORM_SKILLS_TELEMETRY_POWER_PAGES_OPTOUT=1`. Edit `shared/telemetry/` first, refresh `scripts/lib/telemetry/lib` in the same change, and NEVER copy another plugin's `ikey.json`, resolver, instrumentation key, or event stream.
+- **Secret temporary files:** Prefer stdin and keep secrets out of argv, environment variables, logs, and errors. `scripts/store-keyvault-secret.js` demonstrates stdin handling, mode `0600`, and `finally` cleanup; it does not yet provide private-directory or exclusive-creation guarantees. When a tool requires a file, it MUST also create a unique private temporary directory and open the secret file exclusively (`wx` / `O_EXCL`), then remove both in `finally`.
+- **Security regression tests:** Security fixes and security-sensitive code MUST add `node:test` coverage under `scripts/tests/` for inert shell metacharacters, hostile HTML and script-closing text, traversal-style filenames and archive entries, and Windows and POSIX path/process behavior. Tests MUST prove that data remains data and that validation fails closed without placing a working exploit in documentation or fixtures.
+- **Private vulnerability handling:** Suspected exploitable reports MUST stay in a GitHub private security advisory or another approved private channel until remediation and disclosure are coordinated. Do not paste exploit details, secrets, customer data, or working payloads into public issues, PRs, logs, reports, or test output; public changes should describe the affected class and the guardrail.
+
## Telemetry
This plugin ships 1DS telemetry for skill-run and script-run signals. The canonical shared library lives at the repo-root `shared/telemetry/`; `scripts/lib/telemetry/lib` is a physical copy bundled with this plugin so local checkouts and installed plugins do not depend on symlink handling. Zero npm dependencies — nothing to install.