jeffsenso/prestashop-skills / skills/prestashop-module-development
prestashop-module-development
VerifiedComplete PrestaShop module development workflow using modern architecture and best practices. Use when: creating new PrestaShop modules, updating legacy modules to modern code, implementing hooks and actions, setting up module configuration pages, adding front office features, handling database operations, implementing security measures, managing translations, creating cart rules and vouchers, building Symfony console commands, or modernizing existing PrestaShop modules from legacy patterns to current standards.
references/security.md
View on GitHub# Security implementation
Always implement these security measures in every admin form or AJAX endpoint.
## CSRF token validation
In Symfony controllers, CSRF is handled automatically by the framework when forms use `form.factory`. For manual AJAX endpoints, validate the token explicitly:
```php
if (!$this->isCsrfTokenValid('my_action', $request->request->get('_token'))) {
throw $this->createAccessDeniedException('Invalid CSRF token.');
}
```
In legacy controllers:
```php
if (!Tools::getToken(false)) {
$this->context->controller->errors[] = $this->trans('Invalid token', [], 'Admin.Notifications.Error');
return false;
}
```
## Input validation and sanitization
```php
$input = Tools::getValue('input_field');
if (!Validate::isGenericName($input)) {
$this->context->controller->errors[] = $this->trans('Invalid input', [], 'Admin.Notifications.Error');
return false;
}
```
Common `Validate::` methods: `isGenericName`, `isInt`, `isBool`, `isEmail`, `isUrl`, `isHtml`, `isUnsignedInt`.
## SQL injection prevention
Always cast numeric values and escape strings:
```php
// Cast IDs
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'my_table WHERE id = ' . (int) $id;
// Escape strings
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'my_table WHERE name = "' . pSQL($name) . '"';
// DbQuery builder (preferred)
$sql = new DbQuery();
$sql->select('*')
->from('my_table')
->where('id = ' . (int) $id);
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
```
Never interpolate unvalidated request input directly into SQL strings.
## Admin access control
```php
if (!$this->context->employee->hasAccess($this->id, 'edit')) {
throw new PrestaShopException('Access denied');
}
```
In Symfony controllers, use `$this->denyAccessUnlessGranted()` or rely on `_legacy_controller` permission checking built into `FrameworkBundleAdminController`.
## File upload security
Always use `ImageManager::validateUpload()` and provide the full `$_FILES`-compatible array including `name`, `tmp_name`, `type`, `size`, `error`:
```php
$fileData = [
'name' => $_FILES['photo']['name'],
'tmp_name' => $_FILES['photo']['tmp_name'],
'type' => mime_content_type($_FILES['photo']['tmp_name']) ?: 'application/octet-stream',
'size' => $_FILES['photo']['size'],
'error' => $_FILES['photo']['error'],
];
$uploadError = ImageManager::validateUpload($fileData, Tools::getMaxUploadSize());
if ($uploadError) {
// handle error
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |