config = $config; } public function getName(): string { return 'content'; } /** * @param array $input * @return array */ public function detect(Context $context, array $input = []): array { $tmp = (string)($input['tmp'] ?? ''); $size = (int)($input['size'] ?? 0); $realMime = (string)($input['real_mime'] ?? ''); $suspicious = false; $reasons = []; if ($tmp === '' || !is_file($tmp)) { return ['suspicious' => false, 'reasons' => []]; } // Determine limits from Config if provided, otherwise use defaults $maxBytes = 8192; $maxFilesize = 2 * 1024 * 1024; $allowXmlEval = false; $customPatterns = []; if ($this->config instanceof Config) { $maxBytes = (int)$this->config->get('detectors.content.sniff_max_bytes', $this->config->get('limits.sniff_max_bytes', $maxBytes)); $maxFilesize = (int)$this->config->get('detectors.content.sniff_max_filesize', $this->config->get('limits.sniff_max_filesize', $maxFilesize)); $allowXmlEval = (bool)$this->config->get('detectors.content.allow_xml_eval', false); $customPatterns = (array)$this->config->get('detectors.content.custom_patterns', []); } if ($size <= 0) { $size = @filesize($tmp) ?: 0; } if ($size <= 0 || $size > $maxFilesize) { return ['suspicious' => false, 'reasons' => []]; } $bytes = min($maxBytes, $size); $maxlen = $bytes > 0 ? $bytes : null; $head = @file_get_contents($tmp, false, null, 0, $maxlen); if ($head === false || $head === '') { return ['suspicious' => false, 'reasons' => []]; } $scan = $head; // Detect PHP open tags (avoid matching $suspicious, 'reasons' => array_values(array_unique($reasons))]; } }