Skip to content

Commit 8eec43f

Browse files
caseysoftwareclaude
andcommitted
Only save translations for installed modules and languages
translate_save.php built the path of the .inc file it writes from the posted module and lang values without checking them, so a module such as "../../files/probe" wrote files/probe.inc, and other values could write .inc files elsewhere on the server. Only System Admin editors can reach the page, but the files are later read as translations. Both values must now be an installed module (or common/styles) and an installed language; otherwise nothing is written and an error is shown. The editor itself (translate.php) falls back to the defaults for unknown values instead of reading from a path built out of them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CP89WVmGZ1VVCCZMS6ntN
1 parent a16e3f9 commit 8eec43f

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎modules/system/translate.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
// read the installed languages
2222
$locales = $loader->readDirs('locales');
2323

24+
// Both values are used to build file paths below, so fall back to the defaults
25+
// rather than reading from a path built out of an unknown value.
26+
if (!is_string($module) || !isset($modules[$module])) {
27+
$module = 'admin';
28+
}
29+
if (!is_string($lang) || !isset($locales[$lang])) {
30+
$lang = 'en';
31+
}
32+
2433
ob_start();
2534
// read language files from module's locale directory preferably
2635
$localeFile = W2P_BASE_DIR . '/modules/' . $modules[$module] . '/locales/en/' . $modules[$module] . '.inc';

‎modules/system/translate_save.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
$AppUI->redirect(ACCESS_DENIED);
2020
}
2121

22+
// Both values become part of the path of the file that is written below, so
23+
// only an installed module (or the shared common/styles files) and an
24+
// installed language are accepted. Anything else, such as "../", could
25+
// write a file outside the locales folders.
26+
$loader = new w2p_FileSystem_Loader();
27+
$modules = arrayMerge($loader->readDirs('modules'), array('common' => 'common', 'styles' => 'styles'));
28+
$locales = $loader->readDirs('locales');
29+
if (!is_string($module) || !isset($modules[$module]) || !is_string($lang) || !isset($locales[$lang])) {
30+
$AppUI->setMsg('Unknown module or language; the locales file was not saved.', UI_MSG_ERROR);
31+
$AppUI->redirect('m=system&a=translate');
32+
}
33+
2234
// save to core locales if a translation exists there, otherwise save
2335
// into the module's local locale area if it exists. If not then
2436
// the core table is updated.

0 commit comments

Comments
 (0)