Skip to content

Commit c029879

Browse files
authored
Merge pull request #6 from concrete5/fix-xss
Fixing XSS in search
2 parents 43af3d1 + dd28dd1 commit c029879

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

controllers/single_page/search.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function view()
1515

1616
$input = $query->get('keywords');
1717
$filter = $query->get('filter');
18-
$tags = $query->get('tags');
18+
$tags = $this->extractTags($query->get('tags'));
1919
$itemsPerPage = $query->get('ipp');
2020
$filterLabel = 'Anything';
2121

@@ -63,7 +63,7 @@ public function view()
6363
}
6464
} else {
6565
if ($tags) {
66-
foreach ((array)$tags as $tag) {
66+
foreach ($tags as $tag) {
6767
$list->filterByAssetTags($tag);
6868
}
6969
$keywords = $tags;
@@ -122,6 +122,24 @@ public function view()
122122
$this->set('showCollectionResults', $showCollectionResults);
123123
}
124124

125+
/**
126+
* @param mixed $tags
127+
* @return array
128+
*/
129+
protected function extractTags($tags) : array
130+
{
131+
$return = [];
132+
if (is_array($tags)) {
133+
foreach ($tags as $tag) {
134+
$tag = preg_replace('/[<>"\']/', '', $tag);
135+
if ($tag) {
136+
$return[] = $tag;
137+
}
138+
}
139+
}
140+
return $return;
141+
}
142+
125143
public function getRemoveTagUrl($keyword)
126144
{
127145
$url = \URL::to('/search');

single_pages/search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<?php foreach ($keywords as $keyword) {
6666
$tagUrl = $view->controller->getRemoveTagUrl($keyword);
6767
?>
68-
<span><?= $keyword ?> <a href="<?=$tagUrl?>"><i class="fa fa-close"></i></a></span>
68+
<span><?= h($keyword) ?> <a href="<?=$tagUrl?>"><i class="fa fa-close"></i></a></span>
6969
<?php } ?>
7070
</div>
7171
<?php } ?>

0 commit comments

Comments
 (0)