Skip to content
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
4 changes: 2 additions & 2 deletions admin/panels/static/admin.static.delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function ondelete() {
// Clean up input
$id = sanitize_text_field($this->page);

// Validate static pages directly here
if (empty($id) || !preg_match('/^[a-zA-Z0-9-_]+$/', $id)) {
// Keep the existing ASCII admin policy, but share the Core safety check.
if (empty($id) || !static_isvalid($id) || !preg_match('/^[a-zA-Z0-9-_]+$/', $id)) {
// Error status
$this->smarty->assign('success', -1);
return 1;
Expand Down
7 changes: 6 additions & 1 deletion admin/panels/static/admin.static.write.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ function sanitizePageId($id) {
'/[^\p{L}\p{N}_-]/u'
], '', $id);

return trim(str_replace(' ', '', $id));
if (!is_string($id)) {
return '';
}

$id = trim(str_replace(' ', '', $id));
return static_isvalid($id) ? $id : '';
}

function makePageTitle($title, $sep) {
Expand Down
10 changes: 9 additions & 1 deletion fp-includes/core/core.static.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ function static_parse($id) {
}

function static_isvalid($id) {
return preg_match('![^./\\\\]+!', $id);
if (!is_string($id) || $id === '') {
return false;
}

if (strpos($id, "\0") !== false) {
return false;
}

return preg_match('/\A[\p{L}\p{N}_-]+\z/u', $id) === 1;
}

function static_save($entry, $id, $oldid = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function smarty_validate_criteria_isValidEntryId($value, $empty, &$params, &$for
return false;
}

return !preg_match('/[^a-z0-9\-_]/i',$value);
// Keep the existing ASCII editor policy, but share the Core safety check.
return static_isvalid($value) && !preg_match('/[^a-z0-9\-_]/i', $value);
}
?>
18 changes: 16 additions & 2 deletions fp-plugins/prettyurls/plugin.prettyurls.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ function lastcomments_feed_link_atom($str) {
}

function staticlink($str, $id) {
if (!static_isvalid($id)) {
return $str;
}

return $this->baseurl . $id . "/";
}

Expand Down Expand Up @@ -226,8 +230,13 @@ function handle_date($matches) {
}

function handle_static($matches) {
if (!isset($matches [1]) || !static_isvalid($matches [1])) {
return isset($matches [0]) ? $matches [0] : '';
}

$this->fp_params ['page'] = $matches [1];
$this->status = 2;
return '';
}

function handle_entry($matches) {
Expand Down Expand Up @@ -1160,8 +1169,13 @@ function prettyurls_redirect_canonical() {
}
$target = $base . 'page/' . $pn . '/';
} elseif ($has_page) {
$id = preg_replace('/[^A-Za-z0-9_-]/', '', (string) $_GET ['page']);
if ($id === '') {
$rawId = (string) $_GET ['page'];
if (!static_isvalid($rawId)) {
return;
}

$id = preg_replace('/[^A-Za-z0-9_-]/', '', $rawId);
if ($id === '' || !static_isvalid($id)) {
return;
}
// Build via staticlink() to respect all modes
Expand Down
4 changes: 4 additions & 0 deletions sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
$statics = static_getlist();
foreach ($statics as $currentstatic) {
$currentStaticData = static_parse($currentstatic);
if (!is_array($currentStaticData)) {
continue;
}

$loc = BLOG_BASEURL . '?page=' . $currentstatic;

// If current static has no date, use timestamp of now
Expand Down