I know that “you should never trust user input” – this makes a lot of sense when outputting user generated content in HTML or when using user provided data in database calls. All of these cases require different mitigation approaches, different content, different character sequences are considered harmful. So you need to know what you are aiming for before sanitizing data. This is something Kirby also covers in its documentation.
While building a public API endpoint for a Kirby project, I asked myself what: Are there any attact vectors when interacting with Kirby’s pages system?
As a starting point, let’s say I read a page slug from the URL using get('page'). Consider the following scenarios:
- Finding a page:
$page = kirby()->page($page); - Filtering a pages collection:
$page = $pages->filterBy('slug', $page); - Creating content:
$page = $parent->createChild(['slug' => $page, 'content' => ['other' => 'user-provided', 'data' => 'to store']]);
What can go wrong, if I just pass in the raw value from the URL?