Skip to content

Commit 10882e6

Browse files
committed
Improve email validation
1 parent 54c2ece commit 10882e6

9 files changed

Lines changed: 1004 additions & 1006 deletions

File tree

package-lock.json

Lines changed: 970 additions & 969 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
2-
"name": "passky-server",
3-
"description": "Server for Passky (password manager)",
4-
"version": "8.1.7",
5-
"main": "tailwind.config.js",
6-
"scripts": {
7-
"build": "npx tailwindcss -i ./tailwind.css -o ./server/src/website/css/tailwind.min.css --minify"
8-
},
9-
"repository": {
10-
"type": "git",
11-
"url": "git+https://github.com/Rabbit-Company/Passky-Server.git"
12-
},
13-
"author": "Rabbit Company",
14-
"license": "GPL-3.0",
15-
"bugs": {
16-
"url": "https://github.com/Rabbit-Company/Passky-Server/issues"
17-
},
18-
"homepage": "https://github.com/Rabbit-Company/Passky-Server#readme",
19-
"devDependencies": {
20-
"tailwindcss": "^3.4.3"
21-
}
22-
}
2+
"name": "passky-server",
3+
"description": "Server for Passky (password manager)",
4+
"version": "8.1.8",
5+
"main": "tailwind.config.js",
6+
"scripts": {
7+
"build": "npx tailwindcss -i ./tailwind.css -o ./server/src/website/css/tailwind.min.css --minify"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/Rabbit-Company/Passky-Server.git"
12+
},
13+
"author": "Rabbit Company",
14+
"license": "GPL-3.0",
15+
"bugs": {
16+
"url": "https://github.com/Rabbit-Company/Passky-Server/issues"
17+
},
18+
"homepage": "https://github.com/Rabbit-Company/Passky-Server#readme",
19+
"devDependencies": {
20+
"tailwindcss": "^3.4.14"
21+
}
22+
}

server/src/Database.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,8 @@ public static function createAccount(string $username, string $password, string
312312
if($amount_of_accounts >= Settings::getMaxAccounts()) return Display::json(15);
313313
}
314314

315-
$sub_email = filter_var($email, FILTER_SANITIZE_EMAIL);
316-
317315
if(!preg_match("/^[a-z0-9._]{6,30}$/i", $username)) return Display::json(12);
318-
if(!filter_var($sub_email, FILTER_VALIDATE_EMAIL)) return Display::json(6);
316+
if(!preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}$/i", $email) || strlen($email) > 200) return Display::json(6);
319317
if(!preg_match("/^[a-z0-9]{128}$/i", $password)) return Display::json(5);
320318

321319
$username = strtolower($username);
@@ -923,14 +921,15 @@ public static function removeYubiKey(string $username, string $token, string $id
923921

924922
public static function forgotUsername(string $email) : string{
925923
if(!Settings::getMail()) return Display::json(28);
926-
$sub_email = filter_var($email, FILTER_SANITIZE_EMAIL);
927-
if(!filter_var($sub_email, FILTER_VALIDATE_EMAIL)) return Display::json(6);
924+
if(!preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}$/i", $email) || strlen($email) > 200) return Display::json(6);
925+
926+
$email = strtolower($email);
928927

929928
try{
930929
$conn = Settings::createConnection();
931930

932931
$stmt = $conn->prepare('SELECT username FROM users WHERE email = :email');
933-
$stmt->bindParam(':email', $sub_email, PDO::PARAM_STR);
932+
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
934933
$stmt->execute();
935934

936935
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

server/src/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Settings{
2121
*/
2222

2323
public static function getVersion() : string{
24-
return '8.1.7';
24+
return '8.1.8';
2525
}
2626

2727
public static function getLocation() : string{

server/src/website/actions/createLicense.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
session_start();
55

6-
$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
6+
$token = htmlspecialchars(filter_input(INPUT_GET, 'token'), ENT_QUOTES, 'UTF-8');
77

88
if(!isset($_SESSION['username']) || !isset($_SESSION['token']) || !$token || $token !== $_SESSION['token']){
99
$_SESSION['page'] = 'home';

server/src/website/actions/deleteAccount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
session_start();
55

6-
$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
6+
$token = htmlspecialchars(filter_input(INPUT_GET, 'token'), ENT_QUOTES, 'UTF-8');
77

88
if(!isset($_SESSION['username']) || !isset($_SESSION['token']) || !$token || $token !== $_SESSION['token']){
99
$_SESSION['page'] = 'home';

server/src/website/actions/deleteLicense.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
session_start();
55

6-
$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
6+
$token = htmlspecialchars(filter_input(INPUT_GET, 'token'), ENT_QUOTES, 'UTF-8');
77

88
if(!isset($_SESSION['username']) || !isset($_SESSION['token']) || !$token || $token !== $_SESSION['token']){
99
$_SESSION['page'] = 'home';

server/src/website/actions/editAccount.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
session_start();
55

6-
$token = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);
6+
$token = htmlspecialchars(filter_input(INPUT_GET, 'token'), ENT_QUOTES, 'UTF-8');
77

88
if(!isset($_SESSION['username']) || !isset($_SESSION['token']) || !$token || $token !== $_SESSION['token']){
99
$_SESSION['page'] = 'home';
@@ -17,8 +17,6 @@
1717
$disable2fa = ($_GET['disable2fa'] === 'true') ? true : false;
1818
$disablePremium = ($_GET['disablePremium'] === 'true') ? true : false;
1919

20-
$sub_email = filter_var($email, FILTER_SANITIZE_EMAIL);
21-
2220
if(!is_numeric($maxPasswords)) $maxPasswords = Settings::getMaxPasswords();
2321
if($maxPasswords < 0) $maxPasswords = -1;
2422
if($maxPasswords > 1_000_000_000) $maxPasswords = 1_000_000_000;
@@ -28,10 +26,10 @@
2826
try{
2927
$conn = Settings::createConnection();
3028

31-
if(filter_var($sub_email, FILTER_VALIDATE_EMAIL)){
29+
if(preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,}$/i", $email) && strlen($email) <= 200){
3230
$stmt = $conn->prepare('UPDATE users SET email = :email, max_passwords = :maxPasswords WHERE username = :username');
3331
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
34-
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
32+
$stmt->bindParam(':email', strtolower($email), PDO::PARAM_STR);
3533
$stmt->bindParam(':maxPasswords', $maxPasswords, PDO::PARAM_INT);
3634
$stmt->execute();
3735
}else{

server/src/website/css/tailwind.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)