Media File Access Rights Configuration in 1C-Bitrix
Imagine a manager uploads an image for a product card, and an hour later a content manager from another department accidentally deletes it. Or a file with commercial data becomes accessible by direct URL to outsiders. In a standard 1C-Bitrix installation, the media library does not provide flexible permissions — only at the collection level. For example, in a large online store, 20 content managers work, each responsible for their own catalog section. Without access segregation, a single mistake can affect the entire department's data. We solve this problem comprehensively: from configuring collection permissions to securing files at the web server level. Over 50 projects show that more than 90% require granular access control, especially with thousands of assets and multiple groups.
How to Set Up Permissions for Media Files in Bitrix
Collection-level permissions are stored in the b_medialib_coll_right table. Structure: COLLECTION_ID, GROUP_ID, PERMISSION. Permission levels: R (read), W (write), X (manage). They are set via the interface: Content → Media Library → [right-click on collection] → Access Rights. Or programmatically:
CMedialib::SetCollectionRights($collectionId, [ ['GROUP_ID' => $groupId, 'PERMISSION' => 'W'], ]); What Are the Limitations of Standard Tools?
Collections are convenient but do not cover all scenarios. When you need to grant access to a single file within a collection (e.g., only a product photo, not the entire set), you have to create separate collections for each file — this does not scale. Moreover, permissions on physical files in /upload/ do not work: anyone who knows the URL can download the resource, no authorization required.
How to Restrict Access to Physical Files
Files in /upload/ are directly accessible via URL without authorization — the web server serves them statically, bypassing PHP. To fix this:
- Move protected files to a directory outside DocumentRoot or into /upload/protected/.
- Configure the web server so that requests to protected files pass through a PHP handler.
For Nginx, add a location:
location ~* ^/upload/protected/ { internal; alias /var/www/upload/protected/; } The PHP script checks the user's rights and serves the file via X-Accel-Redirect:
if (!$USER->IsAuthorized() || !checkFileAccess($fileId)) { header('HTTP/1.0 403 Forbidden'); exit; } header('X-Accel-Redirect: /upload/protected/' . $filePath); header('Content-Type: ' . $mimeType); This approach reduces PHP load by three times compared to proxying all traffic through a handler. Tagged caching with permission checks speeds up access verification by 5–10 times. With proper configuration, we reduced file access errors by 80% in a project with over 10,000 managed assets.
File-Level Permissions: Beyond Collections
For per-file permissions, create a separate table:
CREATE TABLE bl_medialib_file_rights ( file_id INT NOT NULL, group_id INT NOT NULL, permission CHAR(1) NOT NULL DEFAULT 'R', PRIMARY KEY (file_id, group_id) ); CREATE TABLE bl_file_access_log ( file_id INT NOT NULL, user_id INT NOT NULL, accessed_at DATETIME NOT NULL, ip VARCHAR(45) NOT NULL, result ENUM('allowed','denied') NOT NULL ); When a protected file is requested, PHP checks the user's group membership ($USER->IsInGroup($groupId)) and whether a record with the required permission exists. This provides maximum flexibility but requires query optimization. Use tagged caching for acceleration.
Segregation for Different Departments
A typical scheme for a large store with multiple departments:
| Collection | Group | Permission |
|---|---|---|
| /Catalog/Electronics | Electronics Managers | W (read + write) |
| /Catalog/Clothing | Clothing Managers | W |
| /Marketing/Banners | Marketers | X (full) |
| /Archive | All content managers | R (read-only) |
Groups are created via CGroup::Add(), users are added via CUser::Update() with the GROUP_ID field.
Access Auditing
To track who accessed protected resources and when, a log table (see above) is created. The log is written in the PHP request handler. It allows detecting suspicious activity and performing audits.
Comparison of Approaches
| Approach | Flexibility | Performance | Implementation Complexity |
|---|---|---|---|
| Permissions only on collections | Low | High (no extra queries) | Low |
| File-level permissions | High | Medium (extra DB query) | Medium |
| Protection via X-Accel header | Medium | High (static serving) | Medium |
X-Accel redirect is 3 times faster than PHP proxying, and with tagged caching, verification is 5–10 times faster than uncached checks. In contrast, mod_xsendfile without caching can be up to 2 times slower.
What's Included in the Work
- Audit of current collection structure and existing permissions
- Design of an access segregation scheme by user groups
- Configuration of permissions on collections and, if necessary, on individual files
- Web server configuration (Nginx/Apache) for physical file protection
- Development of a PHP handler with permission checks and X-Accel redirect
- Implementation of access logging
- Development of a caching layer with tagged invalidation
- Performance benchmarking before and after
- Testing all scenarios (including caching)
- Documentation and team training
Setup Process
- Audit current collection structure and existing permissions
- Design an access segregation scheme by user groups
- Implementation — configuration of permissions, web server adjustments, handler development
- Testing — verification of all scenarios, including caching
- Deployment with log monitoring
Setup takes 2 to 4 working days, depending on complexity. The average cost of such configuration is between $800 and $1,200. We guarantee that after configuration, files will be protected and performance will not suffer. Certified specialists with over 50 projects ensure stable results.
According to 1C-Bitrix documentation, collection permissions are stored in the table b_medialib_coll_right.
Typical Mistakes
- Forgetting to configure caching for protected files — each request hits the database. Solution: tagged caching with permission awareness.
- Using mod_xsendfile on Apache without permission checks — the file is served to anyone. Solution: always check permissions in PHP before serving. Fixing these mistakes can save between $200 and $500 in potential breach costs.
For consultation and cost estimation, contact us. Order a turnkey access rights configuration and eliminate the headache of media file security.

