← Back to Pull requests

Honour publish options with `AssetManager::$linkAssets` and add the `files` publish option #21150

Closed
unknown closed this pull request without merging on Nov 25, 2026 11:55 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 17:14 UTC
Author

| Q | A
| ------------- | ---
| Is bugfix? | ✔️
| New feature? | ✔️
| Breaks BC? | ❌ (behaviour change for linkAssets + filters, see UPGRADE.md)
| Fixed issues | -

Problem

With AssetManager::$linkAssets = true, publishDirectory() symlinks the whole sourcePath and silently ignores
these publish options:

  • only, except, caseSensitive

  • beforeCopy, afterCopy (from AssetBundle::$publishOptions and from AssetManager::$beforeCopy / $afterCopy)

  • forceCopy
  • No error and no warning are reported, and the docs don't mention it.

    Security impact

    publishOptions is the documented way to publish only part of a package, and packages often ship server code next
    to their client files. For example:

    class ElFinderAsset extends AssetBundle
    {
        public $sourcePath = '@vendor/studio-42/elfinder'; // css/, js/, img/, sounds/ ... and php/
        public $publishOptions = [
            'only' => ['css/*', 'js/*', 'img/*', 'sounds/*'],
        ];
    }
    

    | linkAssets | published |
    | ------------ | --------------------------------------------------- |
    | false | assets/1a2b3c/{css,js,img,sounds} |
    | true | assets/1a2b3c -> vendor/studio-42/elfinder (all of it) |

    With linkAssets enabled, /assets/1a2b3c/php/*.php becomes reachable. A typical front controller config (.htaccess,
    nginx try_files) serves existing files directly, so those PHP files can be executed outside the application's
    access control
    . The same applies to other filters:

    // meant to hide config and server code, ignored with linkAssets
    'publishOptions' => ['except' => ['/config/', '*.php']],
    
    // global policy in the asset manager, ignored with linkAssets
    'assetManager' => [
        'linkAssets' => true,
        'beforeCopy' => function ($from, $to) {
            return substr($from, -4) !== '.php';
        },
    ],
    

    linkAssets is a global switch, often enabled only in some environments. Turning it on changes what every bundle
    exposes, far from the bundles that rely on the filters.

    Solution

    With linkAssets enabled:

    | publish options | result |
    | ----------------------------------------------------------------------- | ------------------------------------------- |
    | none | whole directory symlinked (unchanged) |
    | only / except / beforeCopy / afterCopy (bundle or manager) | tree recreated, one symlink per file that passes the filters (same files as when copying) |
    | only files (new) | each listed entry symlinked as a whole |

    New files option, an alternative to only for listing published entries explicitly:

    public $publishOptions = [
        'files' => ['css', 'img', 'js', 'sounds'],
    ];
    

  • When copying, it filters exactly like only (callbacks and the dotfile filter apply as usual).

  • With linkAssets and no other filters, assets/1a2b3c/js -> vendor/.../js. Files added to a listed directory are

  • published immediately.
  • It cannot be combined with only / except (InvalidConfigException). Entries are validated: relative, no ..,

  • existing, not overlapping.

    Other details:

  • forceCopy now recreates the symlinks in the per-file and files modes. It still has no effect when the whole

  • directory is symlinked.
  • The directory is built in a temporary directory and renamed into place, so concurrent requests are safe (#6226).

  • An existing whole-directory symlink is replaced when filters apply (relevant with a custom hashCallback, where

  • the directory name survives the upgrade).
  • The directory name is still hash($src), so getPublishedPath() / getPublishedUrl() keep working.
  • Known limitation (same as copy mode): the directory name doesn't depend on the options, so a changed filter applies
    after the published directory is removed or with forceCopy. This is documented.

    Behaviour change: apps that use linkAssets together with filters stop publishing files the filters exclude. The
    CHANGELOG and UPGRADE.md describe it.

    Summary by Sourcery

    Honor asset publishing options when linking assets and add explicit file and directory selection for safer package publishing.

    New Features:

  • Add a files publishing option for explicitly selecting files and directories to publish.
  • Bug Fixes:

  • Honor asset and asset-manager publish filters when linkAssets is enabled, preventing excluded files from being exposed.
  • Enhancements:

  • Support filtered and per-entry symlink publishing with forceCopy refreshes and safe atomic replacement of published directories.
  • Documentation:

  • Document the files option, filtered symlink behavior, callback implications, and upgrade considerations.
  • Tests:

  • Add comprehensive coverage for filtered copying, symlink publishing, files validation, callbacks, force-copy behavior, and concurrent-safe publication.
  • Chores:

  • Document the behavior changes and upgrade guidance for existing linkAssets configurations.
  • Diff: 648 lines (+486 / -162) across 8 files Reviewer: terabytesoftw Review duration: 1121m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 648 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.387
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #21150"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.0% (MEDIUM) · Higher = larger blast radius
    52.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository