Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

Refactor input validation

Miguel Ribeiroe075714d12be
diff --git a/endpoints/categories/category.php b/endpoints/categories/category.php
index b611949..97b5b3c 100644
--- a/endpoints/categories/category.php
+++ b/endpoints/categories/category.php
@@ -1,13 +1,9 @@
<?php
require_once '../../includes/connect_endpoint.php';
+require_once '../../includes/inputvalidation.php';
+
session_start();
-function validate($value) {
- $value = trim($value);
- $value = stripslashes($value);
- $value = htmlspecialchars($value);
- $value = htmlentities($value);
- return $value;
-}
+
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
if (isset($_GET['action']) && $_GET['action'] == "add") {
$categoryName = "Category";
diff --git a/endpoints/currency/currency.php b/endpoints/currency/currency.php
index f1bba72..fa91128 100644
--- a/endpoints/currency/currency.php
+++ b/endpoints/currency/currency.php
@@ -1,13 +1,9 @@
<?php
require_once '../../includes/connect_endpoint.php';
+require_once '../../includes/inputvalidation.php';
+
session_start();
-function validate($value) {
- $value = trim($value);
- $value = stripslashes($value);
- $value = htmlspecialchars($value);
- $value = htmlentities($value);
- return $value;
-}
+
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
if (isset($_GET['action']) && $_GET['action'] == "add") {
$currencyName = "Currency";
diff --git a/endpoints/household/household.php b/endpoints/household/household.php
index d93e1ca..0947003 100644
--- a/endpoints/household/household.php
+++ b/endpoints/household/household.php
@@ -1,13 +1,9 @@
<?php
require_once '../../includes/connect_endpoint.php';
+require_once '../../includes/inputvalidation.php';
+
session_start();
-function validate($value) {
- $value = trim($value);
- $value = stripslashes($value);
- $value = htmlspecialchars($value);
- $value = htmlentities($value);
- return $value;
-}
+
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
if (isset($_GET['action']) && $_GET['action'] == "add") {
$householdName = "Member";
diff --git a/endpoints/subscription/add.php b/endpoints/subscription/add.php
index dfa8d3e..9baa47e 100644
--- a/endpoints/subscription/add.php
+++ b/endpoints/subscription/add.php
@@ -1,6 +1,8 @@
<?php
error_reporting(E_ERROR | E_PARSE);
require_once '../../includes/connect_endpoint.php';
+ require_once '../../includes/inputvalidation.php';
+
session_start();
function sanitizeFilename($filename) {
@@ -9,13 +11,6 @@
return $filename;
}
- function validate($value) {
- $value = trim($value);
- $value = stripslashes($value);
- $value = htmlspecialchars($value);
- $value = htmlentities($value);
- return $value;
- }
function getLogoFromUrl($url, $uploadDir, $name) {
$ch = curl_init($url);
diff --git a/endpoints/user/save_user.php b/endpoints/user/save_user.php
index 49fc333..07c63f1 100644
--- a/endpoints/user/save_user.php
+++ b/endpoints/user/save_user.php
@@ -1,15 +1,9 @@
<?php
require_once '../../includes/connect_endpoint.php';
+ require_once '../../includes/inputvalidation.php';
+
session_start();
- function validate($value) {
- $value = trim($value);
- $value = stripslashes($value);
- $value = htmlspecialchars($value);
- $value = htmlentities($value);
- return $value;
- }
-
function update_exchange_rate($db) {
$query = "SELECT api_key FROM fixer";
$result = $db->query($query);
diff --git a/includes/inputvalidation.php b/includes/inputvalidation.php
new file mode 100644
index 0000000..3725ac6
--- /dev/null
+++ b/includes/inputvalidation.php
@@ -0,0 +1,11 @@
+<?php
+
+function validate($value) {
+ $value = trim($value);
+ $value = stripslashes($value);
+ $value = htmlspecialchars($value);
+ $value = htmlentities($value);
+ return $value;
+}
+
+?>
\ No newline at end of file