Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable21] fix(apps): Fix loading info.xml file #39497

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@
}

public static function init() {
// prevent any XML processing from loading external entities
libxml_set_external_entity_loader(static function () {
return null;
});

Check warning on line 551 in lib/base.php

View check run for this annotation

Codecov / codecov/patch

lib/base.php#L550-L551

Added lines #L550 - L551 were not covered by tests

// calculate the root directories
OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4));

Expand Down
2 changes: 1 addition & 1 deletion lib/private/App/CodeChecker/DatabaseSchemaChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

libxml_use_internal_errors(true);
$loadEntities = libxml_disable_entity_loader(false);
$xml = simplexml_load_file($appPath . '/appinfo/database.xml');
$xml = simplexml_load_string(file_get_contents($appPath . '/appinfo/database.xml'));

Check warning on line 45 in lib/private/App/CodeChecker/DatabaseSchemaChecker.php

View check run for this annotation

Codecov / codecov/patch

lib/private/App/CodeChecker/DatabaseSchemaChecker.php#L45

Added line #L45 was not covered by tests
libxml_disable_entity_loader($loadEntities);


Expand Down
12 changes: 12 additions & 0 deletions lib/private/App/CodeChecker/InfoChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
throw new \RuntimeException("No app with given id <$appId> known.");
}

libxml_set_external_entity_loader(static function ($public, $system, $context) {
if ($system === \OC::$SERVERROOT . '/resources/app-info.xsd'
|| \OC::$SERVERROOT . '/resources/app-info-shipped.xsd') {
return $system;

Check warning on line 50 in lib/private/App/CodeChecker/InfoChecker.php

View check run for this annotation

Codecov / codecov/patch

lib/private/App/CodeChecker/InfoChecker.php#L48-L50

Added lines #L48 - L50 were not covered by tests
}
return null;
});

Check warning on line 53 in lib/private/App/CodeChecker/InfoChecker.php

View check run for this annotation

Codecov / codecov/patch

lib/private/App/CodeChecker/InfoChecker.php#L52-L53

Added lines #L52 - L53 were not covered by tests

$xml = new \DOMDocument();
$xml->load($appPath . '/appinfo/info.xml');

Expand All @@ -68,6 +76,10 @@
}
}

libxml_set_external_entity_loader(static function () {
return null;
});

Check warning on line 81 in lib/private/App/CodeChecker/InfoChecker.php

View check run for this annotation

Codecov / codecov/patch

lib/private/App/CodeChecker/InfoChecker.php#L80-L81

Added lines #L80 - L81 were not covered by tests

return $errors;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/private/App/InfoParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

use OCP\ICache;
use function libxml_disable_entity_loader;
use function simplexml_load_file;
use function simplexml_load_string;

class InfoParser {
/** @var \OCP\ICache|null */
Expand Down Expand Up @@ -65,10 +65,10 @@
libxml_use_internal_errors(true);
if ((PHP_VERSION_ID < 80000)) {
$loadEntities = libxml_disable_entity_loader(false);
$xml = simplexml_load_file($file);
$xml = simplexml_load_string(file_get_contents($file));

Check warning on line 68 in lib/private/App/InfoParser.php

View check run for this annotation

Codecov / codecov/patch

lib/private/App/InfoParser.php#L68

Added line #L68 was not covered by tests

Check failure

Code scanning / Psalm

TaintedFile Error

Detected tainted file handling
libxml_disable_entity_loader($loadEntities);
} else {
$xml = simplexml_load_file($file);
$xml = simplexml_load_string(file_get_contents($file));

Check warning on line 71 in lib/private/App/InfoParser.php

View check run for this annotation

Codecov / codecov/patch

lib/private/App/InfoParser.php#L71

Added line #L71 was not covered by tests

Check failure

Code scanning / Psalm

TaintedFile Error

Detected tainted file handling
}

if ($xml === false) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/MDB2SchemaReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
*/
public function loadSchemaFromFile($file, Schema $schema) {
$loadEntities = libxml_disable_entity_loader(false);
$xml = simplexml_load_file($file);
$xml = simplexml_load_string(file_get_contents($file));

Check warning on line 70 in lib/private/DB/MDB2SchemaReader.php

View check run for this annotation

Codecov / codecov/patch

lib/private/DB/MDB2SchemaReader.php#L70

Added line #L70 was not covered by tests
libxml_disable_entity_loader($loadEntities);
foreach ($xml->children() as $child) {
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@
// Check if appinfo/info.xml has the same app ID as well
if ((PHP_VERSION_ID < 80000)) {
$loadEntities = libxml_disable_entity_loader(false);
$xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml');
$xml = simplexml_load_string(file_get_contents($extractDir . '/' . $folders[0] . '/appinfo/info.xml'));

Check warning on line 347 in lib/private/Installer.php

View check run for this annotation

Codecov / codecov/patch

lib/private/Installer.php#L347

Added line #L347 was not covered by tests
libxml_disable_entity_loader($loadEntities);
} else {
$xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml');
$xml = simplexml_load_string(file_get_contents($extractDir . '/' . $folders[0] . '/appinfo/info.xml'));

Check warning on line 350 in lib/private/Installer.php

View check run for this annotation

Codecov / codecov/patch

lib/private/Installer.php#L350

Added line #L350 was not covered by tests
}
if ((string)$xml->id !== $appId) {
throw new \Exception(
Expand Down
Loading