secure-dev-php

Security rules for PHP code covering how outside input, displayed output, file operations, logs, and secrets must be handled.

In plain words
What is it for?
Use them while writing or reviewing PHP applications, especially code that accepts web requests, reads files, renders HTML, logs data, or checks tokens.
Why use it?
They reduce common problems such as path traversal, cross-site scripting (XSS), leaked sensitive data, and unsafe secret comparisons.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/matank001/cursor-security-rules/secure-dev-php
Clone the repo
git clone --depth 1 https://github.com/matank001/cursor-security-rules
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 564 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00564
Opus 5 $0.00000 $0.00282
Sonnet 5 $0.00000 $0.00113
Haiku 4.5 $0.00000 $0.00056

Measured yesterday against content hash a38710bdfbd4, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

secure-dev-php scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

secure-dev-php.mdc · 46 lines

How it starts

The opening of the file, as written. The whole thing — 46 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Secure PHP Development

These rules apply to all PHP code in the repository and aim to prevent common security vulnerabilities through strict handling of input, output, and execution.

All violations must include a clear explanation of which rule was triggered and why, to help developers understand and fix the issue effectively.

if code is in violation add a comment explaining why. don't generate code that violates these rules.

1. Do Not Use User Input in File Paths

  • Rule: Never use $_GET, $_POST, or any unsanitized input directly in file paths or file operations.

2. Always Sanitize User Input Before Use

  • Rule: All external input (e.g., $_GET, $_POST, $_COOKIE, $_SERVER) must be sanitized before being used in logic, queries, or output.

3. Escape Output to Prevent XSS

  • Rule: Always escape output when rendering user-controlled data into HTML.

4. Do Not Log Sensitive Input or Secrets

  • Rule: Avoid logging passwords, tokens, or personal user data.

5. Use Constant-Time Comparison for Secrets

  • Rule: Secrets such as tokens, signatures, or passwords must be compared using constant-time functions (e.g., hash_equals) to prevent timing attacks.

6. Use Strong Defaults for Encryption

  • Rule: Default encryption settings must use secure algorithms and sufficient key lengths (e.g., RSA ≥ 2048 bits, AES-256).

7. Do Not Use unserialize() on Untrusted Input

  • Rule: The unserialize() function must not be used on data from user input or external sources. Use json_decode() as a safer alternative.

8. Restrict File Includes to Known Values

  • Rule: include, require, include_once, and require_once must only be used with hardcoded or explicitly whitelisted file paths, not values derived from user input.

9. Do Not Create Files Based on Untrusted Input

  • Rule: File creation functions (e.g., fopen, file_put_contents) must not use filenames derived from untrusted input without strict validation.

Read the full file on GitHub · 46 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 46 lines · 564 tokens per session scan A a38710bdfbd4

Subscribe to this mod's changes

secure-dev-php is a cursor rule published in the GitHub repository matank001/cursor-security-rules (379 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 564 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.