Skip to content

Production hardening audit: dead code removal, PHP defensive fixes, nginx regex anchor#34

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/varnish-compatibility-check
Draft

Production hardening audit: dead code removal, PHP defensive fixes, nginx regex anchor#34
Copilot wants to merge 3 commits into
mainfrom
copilot/varnish-compatibility-check

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Six targeted production-readiness fixes across the stack. No behavior changes to intended functionality.

Security

nginx/snippets/spx-upload-limits.conf — overbroad WP REST media location

# Before — matches /wp-json/wp/v2/media-settings, /wp-json/wp/v2/media<anything>
location ~* ^/wp-json/wp/v2/media {

# After — collection endpoint + numeric item IDs only
location ~* ^/wp-json/wp/v2/media(/[0-9]+)?$ {

Unanchored regex applied the 100 m body limit and GET HEAD POST OPTIONS method policy to unintended REST endpoints.

PHP (spx-upload-mimes.php)

  • isset()array_key_exists() on both constant-array key guards (project standard; isset returns false for null-valued keys)
  • Initialize $detected = false before try/finally — variable was undefined if finfo_file() threw before assignment

Dead code removed

  • nginx/maps/spx-high-risk-geo.map — not referenced by any nginx config, not deployed by CI (*.conf glob excludes .map), 2-country content out of sync with the 20+ country list hardcoded in spx-bot-mitigation-logic.conf; deployment comment was actively misleading
  • scripts/__pycache__/spx-update-cloudflare.cpython-312.pyc — committed build artifact

Housekeeping

  • .gitignore: add __pycache__/, *.pyc, *.pyo, *.pyd
  • nginx/conf.d/spx-cloudflare-trust.conf: correct stale script name in auto-generated header (update_cloudflare.pyspx-update-cloudflare.py)

Copilot AI added 2 commits June 19, 2026 22:15
- .gitignore: add Python bytecode patterns (__pycache__/, *.pyc, *.pyo, *.pyd)
- git rm tracked build artifact scripts/__pycache__/spx-update-cloudflare.cpython-312.pyc
- spx-upload-mimes.php: replace isset() with array_key_exists() (×2); initialize $detected = false before try/finally to prevent undefined-variable on unexpected exception
- nginx/maps/spx-high-risk-geo.map: remove orphaned dead file (not included in any nginx conf, not copied by CI *.conf glob, misleading deployment comment)
- nginx/conf.d/spx-cloudflare-trust.conf: correct stale script name in auto-generated header (update_cloudflare.py → spx-update-cloudflare.py)
…match

location ~* ^/wp-json/wp/v2/media was unanchored and matched
/wp-json/wp/v2/media-settings, /wp-json/wp/v2/media<anything> etc.,
applying the 100 m body limit and relaxed method policy to unintended
endpoints.  Anchor to collection + numeric-ID paths only.
Copilot AI requested review from Copilot and removed request for Copilot June 19, 2026 22:17
Copilot AI changed the title Production-readiness hardening audit Production hardening audit: dead code removal, PHP defensive fixes, nginx regex anchor Jun 19, 2026
Copilot AI requested a review from MaximillianGroup June 19, 2026 22:18
@MaximillianGroup

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

…tibility-check

# Conflicts:
#	nginx/snippets/spx-upload-limits.conf
Copilot AI requested review from Copilot and removed request for Copilot June 19, 2026 22:35

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Done. The only conflict was in nginx/snippets/spx-upload-limits.conf where both branches anchored the /wp-json/wp/v2/media regex independently. I resolved it by keeping the version from main (which uses $hard_block_reason and positions the check after limit_except), discarding the stale $block_reason guard from this branch. The merge commit is 54a609f.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants