Problem/Motivation

Since #3308369: Block access to yarn.lock and package.json we block access to yarn.lock.
Core only uses Yarn and does not have a package-lock.json but custom themes could use NPM and have this lock file so it could make sense to also block access to it as a hardening.
For example gin has one: https://git.drupalcode.org/project/gin/-/blob/5.0.x/package-lock.json?re...

Steps to reproduce

  1. Install gin.
  2. Browse to /themes/contrib/gin/package-lock.json.

Proposed resolution

Add package-lock.json to this rule in .htaccess: https://git.drupalcode.org/project/drupal/-/blob/5674bcd77c27bbc82ed92bb...

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Drupal's .htaccess now blocks HTTP access to package-lock.json, alongside the existing protection for package.json and yarn.lock.

Core uses Yarn and does not produce a package-lock.json itself. Contributed or custom themes and modules that use npm can have one.

Sites with a customized .htaccess (including scaffold-managed sites that override the scaffolded file) need to apply the same change: replace package\.json with package(-lock)?\.json in the FilesMatch rule.

Issue fork drupal-3584532

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

prudloff created an issue. See original summary.

scontzen’s picture

Assigned: Unassigned » scontzen

scontzen’s picture

Assigned: scontzen » Unassigned
Status: Active » Needs review

Changed package\.json to package(-lock)?\.json in .htaccess. The web.config was removed from core in #3437335: Remove web.config from 11.x, so no changes needed there.

Tested locally. package-lock.json returned 200 before, 403 after.

smustgrave’s picture

Status: Needs review » Needs work

Test failure seems relevant, may need to update the scaffold files too.

scontzen’s picture

Status: Needs work » Needs review

Thanks. Updated the scaffold file and added test coverage for package-lock.json.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Change LGTM.

  • catch committed 9e0c77f2 on main
    task: #3584532 Block access to package-lock.json files
    
    By: prudloff
    By...
catch’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs release note, +Needs change record

Committed/pushed to main and cherry-picked to 11.x, thanks!

After committing I realised we need a release note and probably a change record - since sites can modify their .htaccess and might need to manually apply the same change.

I've added a stub release note but moving to needs work for fleshing that out and the CR.

  • catch committed e98fe6e5 on 11.x
    task: #3584532 Block access to package-lock.json files
    
    By: prudloff
    By...
scontzen’s picture

Issue summary: View changes

Expanded the release notes snippet.

prudloff’s picture

Status: Needs work » Needs review
Issue tags: -Needs release note, -Needs change record

I drafted a CR.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

LGTM

godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Published the CR.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.