| name | pw-module-filevalidator |
| description | Use when deploying discrete file validation architectures inside ProcessWire assessing security and normalization workflows via FileValidator. |
| risk | safe |
| source | processwire-boost |
| date_added | 2026-04-08 |
Asset & Upload Validation Processing (wire-module-filevalidator)
ProcessWire 3.x explicitly enables security filtering extending entirely separate validation architectures bound to file upload protocols called FileValidators. When any admin or form uploads an asset into InputfieldFile / InputfieldImage classes, a series of linked validation classes sequentially processes the raw files rejecting improper MIME types, checking dimensional scales, validating extension properties, and forcefully mitigating payload injection vulnerabilities directly at the source.
Pre-Computation / Anti-Rationalization Check
Audit the configuration variables verifying system validation logic mapping structurally against these constraints:
- Isolate Logic Focus: A FileValidator should not concern itself mapping where the file lands eventually nor mapping URL access patterns; it strictly exists to perform structural file checking logic upon
public function isValid().
- Destructive Evaluation: Is your validator capable of modifying the file safely inside the system pipeline? Some validators sanitize directly on-the-fly (SVG sanitizers stripping script tags mapping logic dynamically).
- Exceptions Mapping: When an upload violates a critical security condition, do you throw explicit internal
WireException classes securely informing the admin layer of specific failure points efficiently?
Execution Phases
Phase 1: Structuring Independent Security Filters
A core validator maps immediately into the functional layer intercepting the process payload via the native FileValidator structure (often extending standard WireData mapping Module requirements explicitly).
<?php
declare(strict_types=1);
namespace ProcessWire;
class FileValidatorCSV extends WireData implements Module
{
public static function getModuleInfo(): array
{
return [
'title' => 'FileValidator: CSV Security Scanner',
'version' => 101,
'summary' => 'Scans CSV files during upload executing validations guarding against potential embedded payload commands blocking explicitly malicious executions natively.',
'requires' => [
'ProcessWire>=3.0.0',
'PHP>=8.4.0'
]
];
}
public function init(): void
{
$this->addHookAfter('InputfieldFile::fileAdded', $this, 'hookValidateCSV');
}
protected function hookValidateCSV(HookEvent $event): void
{
$pagefile = $event->arguments(0);
if (strtolower($pagefile->ext()) !== 'csv') {
return;
}
$filename = $pagefile->filename();
if (!$this->isValid($filename)) {
@unlink($filename);
$event->replace = true;
$event->return = false;
$this->wire()->log->error("Blocked compromised CSV payload upload operation targeting file: " . $pagefile->name());
throw new WireException($this->_('Upload Rejected: The CSV file violates specific internal macro constraints. Payload operation aborted safely.'));
}
}
public function isValid(string $filename): bool
{
if (!file_exists($filename)) {
return false;
}
$content = file_get_contents($filename);
if (preg_match('/^[\=\+\-\@]/m', $content)) {
return false;
}
return true;
}
}
Phase 2: Interacting natively with Core Components
Certain explicit capabilities provided internally by ProcessWire bypass basic Hooks explicitly configuring direct assignments dynamically resolving module evaluations against distinct UI frameworks securely evaluating explicit configurations natively relying internally upon explicitly provided array validations directly.
Modifying behaviors exclusively inside defined modules limits broad global scope interruptions dynamically configuring specific elements safely. Avoid attaching universally triggering Hooks against InputfieldFile indiscriminately unless specifically demanded; apply evaluations isolated actively depending upon distinct requirements directly mapping localized executions securely.
Essential Tools & Ecosystem
- Active processing parsing
$pagefile->filename() elements definitively testing against localized disk persistence environments.
- Deployment parameters manipulating explicitly handled
WireException mapping exact errors resolving clearly onto localized active form notifications natively.
Copy-Paste Prompts
(Pass these direct prompts to the agent to initiate workflows instantly)
[Deploy Operational Sanitizing Logic Scanner]
"Build an encapsulated module designated FileValidatorPDFAttributes actively configuring functional InputfieldFile::fileAdded processes enforcing hook interceptions securely isolating specific .pdf upload events. Instantiate local PHP structures analyzing incoming file headers mapping exact specific explicit mime types functionally validating file execution parameters safely relying strictly isolating explicit deviations naturally blocking events relying uniquely upon WireException."
Context Awareness (ProcessWire API Docs)
CRITICAL RULE FOR ALL AI AGENTS:
When you need to understand, use, or hook into a ProcessWire core class or module, you MUST NEVER guess or hallucinate the API methods.
- You MUST consult the local AI-optimized Markdown API documentation starting at
.agents/docs/index.md.
- Navigate through the index, find the relevant class document (e.g.
.agents/docs/core/Page.md), and use your file reading tools to read its methods, parameters, and hookable (🪝) events before writing any code.