Skip to content

Security hardening, PHP 8.1+ compatibility, and dependency modernization#14

Draft
Copilot wants to merge 6 commits intoreact-17from
copilot/improve-code-quality
Draft

Security hardening, PHP 8.1+ compatibility, and dependency modernization#14
Copilot wants to merge 6 commits intoreact-17from
copilot/improve-code-quality

Conversation

Copy link

Copilot AI commented Feb 10, 2026

Addresses critical security vulnerabilities, updates dependencies to current stable versions, and removes deprecated PHP functions.

Security Fixes

Path traversal in Template.php

// Before: arbitrary file read via unsanitized input
public function getInlineJs($file) {
    $jsContent = file_get_contents(__DIR__ . '/view/frontend/web/js/' . $file);
    return '<script>' . $jsContent . '</script>';
}

// After: whitelist validation + realpath verification
public function getInlineJs($file) {
    $allowedFiles = ['cash.js', 'custom.js', 'utils.js'];
    if (!in_array($file, $allowedFiles, true)) {
        return '<script>console.error("Invalid JS file requested");</script>';
    }
    $realPath = realpath(__DIR__ . '/view/frontend/web/js/' . $file);
    $expectedDir = realpath(__DIR__ . '/view/frontend/web/js/');
    if ($realPath === false || strpos($realPath, $expectedDir) !== 0) {
        return '<script>console.error("Invalid JS file path");</script>';
    }
    // ...
}

XSS in templates

// Before: unescaped string concatenation
window.productType = "<?=$product->getTypeId();?>";

// After: json_encode prevents injection
window.productType = <?= json_encode($product->getTypeId()) ?>;

Superglobal access replaced with RequestInterface

  • All direct $_GET, $_COOKIE, $_POST replaced with $this->request->getParam()
  • Affected: Template.php, DeferJS.php, DeferCSS.php, RemoveMagentoInitScripts.php

Directory traversal in PostDeployCopy.php

  • Replaced opendir()/readdir() with RecursiveDirectoryIterator
  • Added symlink protection

PHP 8.1+ Compatibility

// Before: deprecated in PHP 8.1+
$mimeType = mime_content_type($imagePath);

// After: using finfo
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $imagePath);
finfo_close($finfo);

Dependency Updates

  • React: 16.8.6 → 18.2.0
  • Webpack: 4.x → 5.89.0
  • Babel: 7.4.x → 7.23.x
  • Updated 15+ npm packages to latest stable

Webpack 5 migration

// Before: Webpack 4 syntax
new CopyWebpackPlugin([{ from: path, to: dest }])

// After: Webpack 5 syntax
new CopyWebpackPlugin({ patterns: [{ from: path, to: dest }] })

Code Quality

  • Removed error suppression (@) operators with proper error handling
  • Added PHPDoc type hints to security-critical methods
  • Fixed typo: curentUenccurrentUenc across codebase
  • Updated unit tests with MockRequest class (replaces direct $_GET manipulation)

Documentation

  • SECURITY.md: Security guidelines, best practices, vulnerability reporting
  • CHANGELOG.md: Migration guide for breaking changes (React 18, Webpack 5)

Verification

  • CodeQL: 0 alerts
  • Code review: No issues
  • Unit tests: Updated and passing
Original prompt

Try to make improvements


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits February 10, 2026 08:53
- Replace deprecated mime_content_type() with finfo_file() for PHP 8.1+ compatibility
- Fix path traversal vulnerability in Template.php getInlineJs() with whitelist validation
- Replace direct $_GET/$_COOKIE access with Magento RequestInterface in all files
- Fix XSS vulnerability in react-header.phtml by using json_encode() for JS output
- Update npm dependencies: React 16→18, Webpack 4→5, Babel 7.4→7.23
- Update webpack.config.js for Webpack 5 compatibility
- Add PHPDoc type hints to security-critical methods

Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
- Fix directory traversal in PostDeployCopy.php using RecursiveDirectoryIterator
- Add symlink protection to prevent traversal attacks
- Remove error suppression operator from react-header.phtml template
- Fix $_GET access in RemoveMagentoInitScripts.php
- Add comprehensive SECURITY.md with security guidelines and best practices
- Document vulnerability reporting process

Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
- Add MockRequest class to Mocks.php implementing RequestInterface
- Update DeferJS.test.php to use MockRequest for testing request parameters
- Update DeferCSS.test.php to use MockRequest for testing request parameters
- Tests now align with security improvements made to production code

Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
- Fixed typo in react-header.phtml template
- Fixed typo in react-core.js
- Fixed typo in react-core.min.js
- Consistent naming across all files

Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
- Document all security fixes and their severity levels
- List all dependency updates with version numbers
- Include breaking changes and migration guide
- Add verification status (code review, CodeQL passed)
- Provide upgrade instructions for users

Co-authored-by: Genaker <9213670+Genaker@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve code quality and maintainability Security hardening, PHP 8.1+ compatibility, and dependency modernization Feb 10, 2026
Copilot AI requested a review from Genaker February 10, 2026 09:04
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