Skip to content

Add prefix-based file access restrictions (RBAC)#1

Open
Copilot wants to merge 3 commits intomainfrom
copilot/restrict-files-by-prefix
Open

Add prefix-based file access restrictions (RBAC)#1
Copilot wants to merge 3 commits intomainfrom
copilot/restrict-files-by-prefix

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 25, 2026

Summary

Implements the ability to restrict files beginning with a certain prefix to specific user groups, as configured in LocalSettings.php.

Changes

New configuration: $wgMixedVisibilityFilesPrefixRestrictions

A map of file name prefixes to required user group(s). Files whose name starts with a configured prefix are restricted to users in the specified group(s).

Example (LocalSettings.php):

$wgMixedVisibilityFilesPrefixRestrictions = [
    'Confidential_' => 'sysop',
    'Internal_' => ['sysop', 'bureaucrat'],
];

With this configuration:

  • File:Confidential_Report.pdf → only accessible by users in the sysop group
  • File:Internal_Memo.pdf → accessible by users in either sysop or bureaucrat groups
  • File:Photo.jpg → existing behavior (anonymous blocked unless __MAKE_FILE_PUBLIC__, registered users allowed)

Implementation details

  • extension.json: Added config section with MixedVisibilityFilesPrefixRestrictions (default: empty). Injected UserGroupManager and MainConfig services into the visibility hook handler.
  • src/VisibilityHooks.php: Updated to check file names against configured prefix restrictions before applying existing anonymous-user logic. For prefix-matched files, anonymous users are always denied and registered users must belong to at least one of the required groups (checked via UserGroupManager::getUserEffectiveGroups).

Behavior

Scenario Before After
No prefix config set Existing behavior Unchanged
File matches prefix, user in required group N/A ✅ Allowed
File matches prefix, user NOT in required group N/A ❌ Denied
File matches prefix, anonymous user N/A ❌ Denied
File doesn't match any prefix Existing behavior Unchanged

Notes

  • Prefix matching is case-sensitive. MediaWiki normalizes the first character of file names to uppercase, so prefixes should start with an uppercase letter.
  • The config value supports both a single group name (string) and multiple group names (array of strings).

Security Summary

No security vulnerabilities were discovered. CodeQL found no analyzable code changes.

Copilot AI and others added 2 commits March 25, 2026 22:27
Introduce MixedVisibilityFilesPrefixRestrictions config that maps file
name prefixes to required user group(s). Files matching a prefix are
restricted to users in the specified group(s), enforced via the
getUserPermissionsErrorsExpensive hook.

Config example in LocalSettings.php:
$wgMixedVisibilityFilesPrefixRestrictions = [
    'Confidential_' => 'sysop',
    'Internal_' => ['sysop', 'bureaucrat'],
];

Co-authored-by: jeffw16 <11380894+jeffw16@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mywikis/MixedVisibilityFiles/sessions/ccc440fc-ea21-44b8-8881-495abcb9bcd6
extension.json Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change 1.39.15 to the latest version of 1.39

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to 1.39.17 (the latest 1.39 release) in ebf8c18.

@jeffw16 jeffw16 marked this pull request as ready for review March 26, 2026 16:53
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