Back to Main Site

10-Layer Pure-PHP File Security, GD Image CDR, ClamAV & Multi-Session Governance for Perfex CRM

Accepting file uploads from internal staff, Client Portal users, and 9 external messaging channels makes chat storage a prime target for polyglot webshells, malicious PDFs, Zip Bombs, and VBA macro payloads. PolyUtilities for Perfex CRM v3.7.0 protects every attachment through Poly_omnichat_file_security: a 10-layer pure-PHP defense-in-depth pipeline featuring 25MP PHP GD Image CDR, deep PDF/ZIP/Office macro inspection, optional socket-based ClamAV zINSTREAM, SSRF DNS pinning, and BOLA/IDOR concurrency hardening verified by 789/789 automated PHP assertions and 32/32 live 6-session concurrent stress checks.

Complete 10-Layer Pure-PHP File Security Architecture

Configured under OmniChat & AI Hub > Settings > Governance & Purge, every file uploaded by staff, sent from the Client Portal, or downloaded automatically from WhatsApp, Messenger, Instagram, Telegram, Slack, Viber, or Zalo passes through all applicable layers on a staging file before touching permanent storage. Zero shell exec commands and zero Node.js daemons are used anywhere in the pipeline.

PolyUtilities v3.7.0 Governance and Purge Settings Showing 10-Layer File Security, GD Image CDR, and ClamAV

Security Layer Exact Enforcement Logic in Poly_omnichat_file_security Threats Neutralized
1. Filename & RTLO Sanitization Blocks null bytes (\0), hidden dotfiles, Unicode BiDi/RTLO spoofing (U+202E, U+202A-U+202E, U+2066-U+2069), and dangerous double-extension tokens (.php.jpg, .exe.pdf, .svg, .html) Right-to-Left Override extension spoofing, Apache multi-extension execution, stored SVG/HTML XSS
2. Magic-Bytes + finfo Cross-Check Reads raw binary headers (MZ, \x7FELF, Mach-O/Java cafebabe, #! shebang) alongside PHP finfo and cross-validates against the strict extension-to-MIME map Renamed Windows PE/Linux ELF binaries, shell scripts, and spoofed Content-Type headers
3. Webshell & Script Scanner Scans head (512KB) and tail (64KB) in O(1) memory for PHP open/short tags, dangerous eval/exec sinks, <script>/<svg>/<iframe> tags, and legacy OLE2 VBA streams (_VBA_PROJECT_CUR) PHP/GIF image polyglots, CSV/TXT XSS payloads, and legacy .doc/.xls/.ppt macros
4. PHP GD 25MP Image CDR Enforces max dimension of 8192px and max 25MP (25,000,000 pixels), then re-encodes JPEG (quality 90), PNG (level 6), and WebP (quality 88) onto a fresh GD canvas Decompression pixel-flood DoS bombs, EXIF/GPS privacy leaks, and appended stego/polyglot payloads
5. Deep PDF Active-Content Scan Inspects up to 4MB of PDF object structure for /JavaScript, /JS, /Launch, /OpenAction payloads, /RichMedia, /XFA, /SubmitForm, /ImportData, /GoToR, and executable /EmbeddedFile objects Weaponized invoice PDFs, automatic script launch exploits, and credential-phishing PDF forms
6. ZIP & OOXML Archive Scanner Uses PHP ZipArchive to cap at 500 entries, 50MB uncompressed size, 100:1 compression ratio, reject ../ or drive-letter paths, block hidden executables, and reject Office vbaProject.bin / vbaData.xml / /macrosheets/ / /vba/ Zip Bombs, Zip Slip directory traversal, archive-wrapped malware, and .docx/.xlsx/.pptx VBA macro droppers
7. Optional Pure-PHP ClamAV Daemon Streams file bytes directly to local clamd via PHP stream_socket_client() using the zINSTREAM protocol over TCP (127.0.0.1:3310) or Unix socket (/var/run/clamav/clamd.ctl) with optional Strict Fail-Closed mode Known malware signatures, trojans, ransomware droppers, and EICAR test files with zero shell_exec()
8. Random Names & .htaccess Hardening Saves accepted files with random 128-bit names under uploads/poly_utilities/omnichat/ guarded by auto-managed .htaccess (Options -Indexes -ExecCGI, php_flag engine off, X-Content-Type-Options: nosniff, sandbox CSP, Content-Disposition: attachment for docs) and index.html Direct PHP execution in uploads, MIME sniffing attacks, and directory indexing
9. Server-Side realpath() Attachment Firewall sanitize_outbound_attachments() on send_message() caps at 5 attachments per message, blocks javascript:, data:, vbscript:, file:, and forged external URLs, validates realpath() strictly inside uploads/poly_utilities/omnichat/, and rebuilds canonical URLs server-side Stored XSS via forged attachment JSON, Local File Inclusion (LFI), and server path disclosure
10. Per-Staff Upload Rate Limiter Rolling 60-second bucket tracked in Poly_omnichat_cache (default 20 files/min/staff, configurable 1 to 300) Storage exhaustion DoS from compromised sessions or scripted upload floods

How to Enable Optional ClamAV zINSTREAM Scanning on a VPS

All 9 core layers work out of the box on standard shared hosting with zero extra binaries. If you run Perfex CRM on a Linux VPS (Ubuntu, Debian, AlmaLinux, or CyberPanel), you can activate Layer 7 real-time antivirus scanning in 3 steps:

  1. Install and start clamav-daemon on your server (sudo apt install clamav-daemon, $0 open-source license, and verify clamd listens on TCP 127.0.0.1:3310 or Unix socket /var/run/clamav/clamd.ctl). OmniChat connects with a 3s socket handshake timeout, streams 8KB (8192-byte) zINSTREAM chunks, and enforces a 15s scan timeout so PHP workers never hang.
  2. Open OmniChat & AI Hub > Settings > Governance & Purge, enable ClamAV Antivirus Scan (clamav_enabled), and enter 127.0.0.1 + port 3310 (or the Unix socket path).
  3. Decide between Fail-Open (skips ClamAV cleanly if clamd restarts while keeping Layers 1 to 6 and 8 to 10 active) or Strict Fail-Closed (clamav_fail_closed: blocks uploads whenever clamd is unreachable), then click Save.

Inbound Media SSRF Defense, Profanity Filter & Cron Data Retention

Beyond direct staff uploads, HeadRandom engineered three additional governance layers for PolyUtilities for Perfex CRM v3.7.0:

  • SSRF DNS Pinning (CURLOPT_RESOLVE) on Channel Media: Whenever WhatsApp, Messenger, Instagram, Telegram, Slack, Viber, or Zalo delivers an inbound voice note or image, Poly_omnichat_media_service enforces HTTPS port 443 only, rejects raw IP literals, matches exact host/CDN suffix allowlists (.fbcdn.net, .cdninstagram.com, .zdn.vn, etc.), verifies every resolved IPv4 via FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE, and pins the validated IP directly into cURL via CURLOPT_RESOLVE to block DNS rebinding SSRF attacks.
  • Profanity Filter: Under Governance & Purge, toggle profanity_filter_enabled and supply comma-separated blocked_words to mask or flag policy-violating terms automatically.
  • Automated Data Retention Purge (Perfex Cron): Set auto_purge_months (0 retains history indefinitely; 1 to 120 months automatically prunes aged conversations on Perfex CRM's after_cron_run schedule). Administrators can also run targeted Manual Purge actions by scope protected by Admin RBAC and accessible double-confirmation modals (never native window.confirm).

Multi-Session Concurrency & BOLA/IDOR Verification

Real-world CRM chat runs with Administrators, Group Owners, Standard Staff, Out-of-Scope Staff, Client Contacts, and Anonymous Guests hitting endpoints simultaneously. Before shipping v3.7.0, HeadRandom validated OmniChat under 7 automated PHP test suites (789/789 assertions passed) and a 6-session live concurrent HTTPS stress test (32/32 checks passed) covering:

  1. Object-Level BOLA/IDOR Enforcement: Non-participants cannot read, reply to, mark read, export, or trigger AI Copilot on private DMs, private groups, or unauthorized Perfex tickets (staff_can_access_ticket).
  2. Group Join & Re-Join History Boundary (last_message_id + 1): Verified across live leave-and-rejoin cycles so historical messages posted during absence remain strictly unreachable via both UI and before_id cursor queries.
  3. Owner-Only Group Membership & mark_read() DM Integrity: Non-owners attempting manage_group_members() are rejected with HTTP 403, cross-conversation reply_to_message_id spoofing is blocked, and mark_read() updates only verified participant rows.
  4. OWASP API3 Non-Admin Data Minimization: Non-admin bootstrap() payloads strip sensitive provider configuration, encrypted keys, and admin-only governance flags before serialization.
  5. Atomic LOCK_EX Cache Consistency: Parallel concurrent writes across 6 active sessions verified zero corrupted JSON cache files and zero stale unread badge races in Poly_omnichat_cache.

Explore how this security architecture underpins every part of v3.7.0 across the Executive Master Dashboard Hub, Unified 3-Panel Inbox, Multi-Provider AI Hub & Voice/Vision, Perfex Ticket AI Copilot, and AIO Support 2.0 Client Portal Live Chat. For initial deployment, follow the PolyUtilities Installation Guide, or contact HeadRandom's custom Perfex CRM module engineering service for specialized compliance audits.

Ready to bring hardened, enterprise-grade communication and AI security into your self-hosted Perfex CRM? Visit the PolyUtilities for Perfex CRM product page to review full specifications and live demo access.

Frequently Asked Questions

Does PolyUtilities File Security require ClamAV to protect my Perfex CRM server?

No. Nine of the ten defense layers (RTLO/double-extension blocking, magic-bytes + finfo cross-checks, webshell signature scanning, PHP GD 25MP Image CDR, deep PDF scanning, ZIP/OOXML Bomb/Slip/Macro inspection, .htaccess hardening, realpath() Attachment Firewall, and per-staff upload rate limiting) run in 100% pure PHP on any shared host. ClamAV (clamd) is an optional tenth layer for VPS servers.

How does PHP GD Image CDR remove hidden malware from customer photos?

After verifying dimensions (up to 8192px and 25MP) to prevent memory exhaustion, sanitize_image_cdr() decodes the uploaded JPEG, PNG, or WebP image pixels onto a brand-new GD truecolor canvas and re-encodes the file from scratch. This process strips EXIF/GPS metadata and destroys appended PHP polyglots or steganographic script payloads while preserving crisp visual quality.

Will legitimate .docx or .xlsx office files be blocked by the Archive Scanner?

No. Standard macro-free .docx, .xlsx, and .pptx files are inspected via ZipArchive and allowed automatically (including their normal internal .xml and .rels metadata). The scanner blocks only unsafe archives containing VBA Macros (vbaProject.bin, vbaData.xml), hidden executables, Zip Slip ../ entries, or Zip Bombs exceeding 50MB uncompressed or a 100:1 compression ratio.

Does PolyUtilities File Security also inspect images and voice notes arriving from WhatsApp or Telegram?

Yes. Every inbound attachment downloaded by Poly_omnichat_media_service from external messaging webhooks passes through HTTPS allowlist validation, SSRF DNS pinning (CURLOPT_RESOLVE), and the full Poly_omnichat_file_security::inspect_and_harden_file() pipeline before being stored permanently or passed to AI Vision and Voice STT.

What happens if ClamAV daemon restarts while a staff member uploads a PDF?

In the default Fail-Open mode, if clamd is temporarily unreachable over TCP 3310 or Unix socket, the upload still passes through all 9 pure-PHP defense layers (including Deep PDF /JavaScript and /Launch scanning). Compliance-strict teams can toggle Strict Fail-Closed mode to reject uploads whenever clamd is offline.

PolyUtilities boosts Perfex CRM with powerful customization and workflow enhancements. Create multi-level menus, group menus by purpose, embed iframe links, open content in popups, and reorganize system navigation with drag-and-drop. Add dynamic widgets across dozens of display positions, use right-click navigation, manage custom JS/CSS, support multi-company and multi-address structures, and convert selected text into tasks instantly. Combined with banners, announcements, quick-access shortcuts, and many smart utilities, PolyUtilities turns Perfex CRM into a faster, cleaner, and highly personalized workspace for every team member.

HeadRandom Perfex CRM Engineering

Need a Custom Perfex CRM Module, Bug Fix, or CodeIgniter 4 Upgrade?

Avoid broken updates, PHP 8.2-8.4 errors, and risky core edits. HeadRandom provides custom Perfex CRM module development, upgrade, and bug-fixing services for any third-party or custom module on your Perfex CRM installation, plus upgrading Perfex CRM from CodeIgniter 3 to CodeIgniter 4 via IgniteCore for Perfex CRM.

Build, Upgrade & Fix Any Perfex CRM Module

Develop new custom modules from scratch, patch bugs or hook conflicts on existing client modules, and update legacy code for clean PHP 8.2-8.4 compatibility with zero core file hacks. View Perfex CRM module development scope.

CodeIgniter 3 to CodeIgniter 4 via IgniteCore

Migrate your Perfex CRM runtime to CodeIgniter 4 (4.7.6) using IgniteCore for Perfex CRM (independent module by HeadRandom) with Dual-Mode CI3 fallback, 32% to 75% lower latency, 50% less RAM, and custom CI4 porting for third-party modules. See CI3 to CI4 upgrade options.

40+ Commercial Modules Published100% Zero Core File Edits0 High Security Audit GateTransparent Pricing from $39

Combine 2+ HeadRandom services (Custom Module, IgniteCore CI4 Upgrade, or Website Care) to save 30% automatically.