master
bernd input-filtering

bernd authored 16 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

5) Written by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
12) */
bernd input-filtering

bernd authored 16 years ago

13) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

14) require_once('inc/error.php');
Hanno Böck move crypt password hash ve...

Hanno Böck authored 4 months ago

15) require_once('inc/base.php');
Hanno Böck replace cracklib with zxcvbn

Hanno Böck authored 7 years ago

16) require_once('vendor/autoload.php');
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

17) 
Hanno Böck move crypt password hash ve...

Hanno Böck authored 4 months ago

18) function gen_pw_hash($password)
19) {
Hanno Böck Use yescrypt instead of SHA...

Hanno Böck authored 4 months ago

20)     /* For yescrypt, a 128 bit salt in non-standard base64 is
21)        needed. We just need random data with valid encoding. */
22)     $salt = base64_encode(random_bytes(16));
23)     $salt = rtrim($salt, "=");
24)     $salt = strtr($salt, "AQgw+/01", "./01AQgw");
25)     $pwhash = crypt($password, '$y$j9T$' . $salt);
Hanno Böck move crypt password hash ve...

Hanno Böck authored 4 months ago

26)     if (strlen($pwhash) < 13) {
27)         /* returns a string shorter than 13 chars on failure */
28)         system_failure("Failed to calculate password hash!");
29)     }
30)     return $pwhash;
31) }
32) 
Hanno Böck use real password hashes fo...

Hanno Böck authored 3 months ago

33) 
34) function legacy_pw_verify($password, $hash)
35) {
36)     /* Supports legacy SHA1/SHA256 hashes without salt,
37)        for new use cases use password_verify() instead */
38)     if ($hash[0] == '$') {
39)         return password_verify($password, $hash);
40)     } elseif (strlen($hash) == 40) {
41)         return hash_equals(sha1($password), $hash);
42)     } elseif (strlen($hash) == 64) {
43)         return hash_equals(hash("sha256", $password), $hash);
44)     }
45)     return false;
46) }
47) 
48) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

49) function strong_password($password, $user = [])
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

50) {
Bernd Wurst support online check for pa...

Bernd Wurst authored 5 years ago

51)     $pwcheck = config('pwcheck');
52)     $result = null;
53)     if ($pwcheck) {
54)         DEBUG($pwcheck);
Bernd Wurst use POST for password checker

Bernd Wurst authored 5 years ago

55)         $req = curl_init($pwcheck);
Bernd Wurst support online check for pa...

Bernd Wurst authored 5 years ago

56)         curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
57)         curl_setopt($req, CURLOPT_SSL_VERIFYPEER, 1);
58)         curl_setopt($req, CURLOPT_SSL_VERIFYSTATUS, 1);
59)         curl_setopt($req, CURLOPT_CONNECTTIMEOUT, 5);
60)         curl_setopt($req, CURLOPT_TIMEOUT, 5);
61)         curl_setopt($req, CURLOPT_FOLLOWLOCATION, 0);
Bernd Wurst use POST for password checker

Bernd Wurst authored 5 years ago

62)         curl_setopt($req, CURLOPT_POST, 1);
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

63)         curl_setopt($req, CURLOPT_POSTFIELDS, "password=" . urlencode($password));
Bernd Wurst support online check for pa...

Bernd Wurst authored 5 years ago

64)         $result = chop(curl_exec($req));
65)         DEBUG($result);
66)     }
67)     if ($result === 'good') {
68)         return true;
69)     } elseif ($result === 'bad') {
Bernd Wurst better error message for we...

Bernd Wurst authored 5 years ago

70)         return "Unsere Überprüfung hat ergeben, dass dieses Passwort in bisher veröffentlichten Passwortlisten enthalten ist. Es wird daher nicht akzeptiert.";
Bernd Wurst support online check for pa...

Bernd Wurst authored 5 years ago

71)     }
Bernd Wurst use Zxcvbn as fallback in e...

Bernd Wurst authored 5 years ago

72)     // Kein Online-Check eingerichtet oder der request war nicht erfolgreich
73)     DEBUG('using Zxcvbn for password check!');
74)     $passwordchecker = new ZxcvbnPhp\Zxcvbn();
Bernd Wurst PHP 8.0 compatibility

Bernd Wurst authored 3 years ago

75)     if ($user) {
76)         $strength = $passwordchecker->passwordStrength($password, $user);
77)     } else {
78)         $strength = $passwordchecker->passwordStrength($password);
79)     }
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

80)     DEBUG('password strength: ' . $strength['score']);
Bernd Wurst use Zxcvbn as fallback in e...

Bernd Wurst authored 5 years ago

81)     if ($strength['score'] < 2) {
82)         return "Das Passwort ist zu einfach!";
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

83)     }
84)     return true;
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

85) }
86) 
87) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

88) function filter_input_general($input)
bernd input-filtering

bernd authored 16 years ago

89) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

90)     if ($input === null) {
91)         return null;
92)     }
Bernd Wurst accept integer parameters i...

Bernd Wurst authored 4 years ago

93)     $input = (string) $input;
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

94)     $filtered = preg_replace('/[\x00-\x09\x0b-\x0c\x0e-\x1f]/', '', $input);
95)     if ($filtered !== $input) {
96)         system_failure("Ihre Daten enthielten ungültige Zeichen!");
97)         logger(LOG_WARNING, 'inc/security', 'filter_input_general', 'Ungültige Daten!');
98)     }
99)     return $filtered;
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

100) }
101) 
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

102) function filter_input_oneline($input)
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

103) {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

104)     if ($input === null) {
105)         return null;
106)     }
Bernd Wurst accept integer parameters i...

Bernd Wurst authored 4 years ago

107)     $input = (string) $input;
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

108)     $filtered = preg_replace('/[\x00-\x1f]/', '', $input);
109)     if ($filtered !== $input) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

110)         system_failure("Ihre Daten enthielten ungültige Zeichen!");
Bernd Wurst accept integer parameters i...

Bernd Wurst authored 4 years ago

111)         logger(LOG_WARNING, 'inc/security', 'filter_input_oneline', 'Ungültige Daten!');
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

112)     }
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

113)     return $filtered;
bernd input-filtering

bernd authored 16 years ago

114) }
115) 
116) 
Bernd Wurst New function filter_output_...

Bernd Wurst authored 4 years ago

117) function filter_output_html($data)
118) {
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

119)     if (!$data) {
Bernd Wurst upgrade dependancies

Bernd Wurst authored 2 years ago

120)         return "";
121)     }
Bernd Wurst New function filter_output_...

Bernd Wurst authored 4 years ago

122)     return htmlspecialchars($data, ENT_QUOTES);
123) }
124) 
125) 
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

126) function verify_input_ascii($data)
127) {
Bernd Wurst accept integer parameters i...

Bernd Wurst authored 4 years ago

128)     $data = (string) $data;
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

129)     $filtered = filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
130)     if ($filtered != $data) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

131)         logger(LOG_WARNING, 'inc/security', 'verify_input_ascii', 'Ungültige Daten: ' . $data);
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

132)         system_failure("Ihre Eingabe enthielt ungültige Zeichen");
133)     }
134)     return $filtered;
135) }
136) 
137) 
138) function verify_input_identifier($data)
139) {
Bernd Wurst accept integer parameters i...

Bernd Wurst authored 4 years ago

140)     $data = (string) $data;
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

141)     if ($data === "") {
142)         system_failure("Leerer Bezeichner");
143)     }
144)     $filtered = preg_replace("/[^[:alnum:]\_\.\-]/", "", $data);
145)     if ($filtered !== $data) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

146)         logger(LOG_WARNING, 'inc/security', 'verify_input_identifier', 'Ungültige Daten: ' . $data);
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

147)         system_failure("Ihre Daten enthielten ungültige Zeichen!");
148)     }
149)     return $filtered;
150) }
151) 
Bernd Wurst New function filter_output_...

Bernd Wurst authored 4 years ago

152) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

153) function filter_input_username($input)
bernd input-filtering

bernd authored 16 years ago

154) {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

155)     $username = preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

156)     if ($username === "") {
157)         system_failure("Leerer Benutzername!");
158)     }
159)     return $username;
hanno Hatte die Kompatibilität ge...

hanno authored 16 years ago

160) }
161) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

162) function verify_input_username($input)
hanno Hatte die Kompatibilität ge...

hanno authored 16 years ago

163) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

164)     if (filter_input_username($input) != $input) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

165)         logger(LOG_WARNING, 'inc/security', 'verify_input_username', 'Ungültige Daten: ' . $input);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

166)         system_failure("Ihre Daten enthielten ungültige Zeichen!");
167)     }
bernd input-filtering

bernd authored 16 years ago

168) }
169) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

170) 
171) 
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 7 months ago

172) function filter_input_hostname($input, $wildcard = false)
bernd check auf hostname

bernd authored 16 years ago

173) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

174)     DEBUG('filter_input_hostname("' . $input . '", $wildcard=' . $wildcard . ')');
Hanno Spezialbehandlung für äöü n...

Hanno authored 5 years ago

175)     $input = strtolower($input);
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

176)     $input = trim($input, "\t\n\r\x00 .");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

177)     if (preg_replace("/[^.]_/", "", $input) != $input) {
178)         system_failure("Der Unterstrich ist nur als erstes Zeichen eines Hostnames erlaubt.");
179)     }
Hanno Spezialbehandlung für äöü n...

Hanno authored 5 years ago

180)     if (preg_replace("/[^[:alnum:]_*\.\-]/u", "", $input) != $input) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

181)         system_failure("Ihre Daten enthielten ungültige Zeichen!");
182)     }
183)     if (preg_match("/^.+\*/", $input)) {
184)         system_failure("Ihre Daten enthielten ungültige Zeichen (Wildcard-Stern muss ganz vorne stehen)!");
185)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

186)     if (!$wildcard && preg_replace("/^\*/", "", $input) != $input) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

187)         system_failure("Ihre Daten enthielten ungültige Zeichen (Keine Wildcards erlaubt)!");
188)     }
189)     if (strstr($input, '..')) {
190)         system_failure("Ungültiger Hostname");
191)     }
192)     return $input;
bernd check auf hostname

bernd authored 16 years ago

193) }
194) 
Hanno Böck codingstyle, spaces between...

Hanno Böck authored 7 months ago

195) function verify_input_hostname($input, $wildcard = false)
bernd Add IP-address patterns

bernd authored 15 years ago

196) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

197)     if (filter_input_hostname($input, $wildcard) != $input) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

198)         logger(LOG_WARNING, 'inc/security', 'verify_input_hostname', 'Ungültige Daten: ' . $input);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

199)         system_failure("Ihre Daten enthielten ungültige Zeichen!");
200)     }
bernd Add IP-address patterns

bernd authored 15 years ago

201) }
202) 
203) 
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

204) function verify_input_hostname_utf8($input)
205) {
206)     $puny = idn_to_ascii($input, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
207)     if ($puny === false) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

208)         system_failure("Ungültiger Hostname! idn " . $input);
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

209)     }
210)     $filter = filter_var($puny, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

211)     if ($filter !== $puny) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

212)         system_failure("Ungültiger Hostname! filter " . $input);
Hanno Böck vhost-hostnamen vernünftig...

Hanno Böck authored 5 years ago

213)     }
214) }
215) 
216) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

217) function verify_input_ipv4($input)
bernd Add IP-address patterns

bernd authored 15 years ago

218) {
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

219)     if (!preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $input)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

220)         system_failure('Keine IP-Adresse');
221)     }
bernd Add IP-address patterns

bernd authored 15 years ago

222) }
223) 
224) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

225) function verify_input_ipv6($input)
bernd Add IP-address patterns

bernd authored 15 years ago

226) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

227)     // ripped from Perl module Net-IPv6Addr v0.2
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

228)     if (!preg_match("/^(([0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|[0-9a-f]{0,4}::|:(?::[a-f0-9]{1,4}){1,6}|(?:[a-f0-9]{1,4}:){1,6}:|(?:[a-f0-9]{1,4}:)(?::[a-f0-9]{1,4}){1,6}|(?:[a-f0-9]{1,4}:){2}(?::[a-f0-9]{1,4}){1,5}|(?:[a-f0-9]{1,4}:){3}(?::[a-f0-9]{1,4}){1,4}|(?:[a-f0-9]{1,4}:){4}(?::[a-f0-9]{1,4}){1,3}|(?:[a-f0-9]{1,4}:){5}(?::[a-f0-9]{1,4}){1,2}|(?:[a-f0-9]{1,4}:){6}(?::[a-f0-9]{1,4}))$/i", $input)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

229)         system_failure("Ungültige IPv6-Adresse");
230)     }
bernd Add IP-address patterns

bernd authored 15 years ago

231) }
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

232) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

233) function verify_input_recorddata($input)
Hanno Böck Prüfe DNS-Records auf probl...

Hanno Böck authored 7 years ago

234) {
Bernd Wurst warnings vermeiden

Bernd Wurst authored 6 days ago

235)     if (is_string($input) && (strstr($input, "\\") || strstr($input, '"'))) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

236)         system_failure("Ungültige Zeichen");
237)     }
Hanno Böck Prüfe DNS-Records auf probl...

Hanno Böck authored 7 years ago

238) }
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

239) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

240) function filter_quotes($input)
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

241) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

242)     return preg_replace('/["\'`]/', '', $input);
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

243) }
244) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

245) 
246) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

247) function filter_shell($input)
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

248) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

249)     return preg_replace('/[^-[:alnum:]\_\.\+ßäöüÄÖÜ/%§=]/', '', $input);
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

250) }
251) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

252) function verify_shell($input)
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

253) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

254)     if (filter_shell($input) != $input) {
255)         system_failure("Ihre Daten enthielten ungültige Zeichen!");
256)     }
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

257) }
bernd input-filtering

bernd authored 16 years ago

258) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

259) 
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 7 years ago

260) function filter_ssh_key($key)
261) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

262)     $keyparts = explode(" ", trim($key));
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 7 years ago

263) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

264)     if ((count($keyparts) > 3) || (count($keyparts) < 2)) {
265)         system_failure("Ungültiger SSH-Key!");
266)     }
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 7 years ago

267) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

268)     if (preg_match("/^[a-z0-9]+-[a-z0-9-]+$/", $keyparts[0]) === 0) {
269)         system_failure("Ungültiger SSH-Key!");
270)     }
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 7 years ago

271) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

272)     if (base64_decode($keyparts[1], 1) == false) {
273)         system_failure("Ungültiger SSH-Key!");
274)     }
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 7 years ago

275) 
Hanno Böck fix regular expression (was...

Hanno Böck authored 3 years ago

276)     if ((count($keyparts) === 3) && (preg_match("/^[a-zA-Z0-9@._-]+$/", $keyparts[2]) === 0)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

277)         system_failure("Ungültige Zeichen im Kommentar des SSH-Keys!");
278)     }
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 7 years ago

279) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

280)     if (count($keyparts) === 2) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

281)         return $keyparts[0] . " " . $keyparts[1];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

282)     } else {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

283)         return $keyparts[0] . " " . $keyparts[1] . " " . $keyparts[2];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

284)     }
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 7 years ago

285) }
286) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

287) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

288) function check_path($input)
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

289) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

290)     DEBUG("checking {$input} for valid path name");
Bernd Wurst New function filter_output_...

Bernd Wurst authored 4 years ago

291)     if ($input != filter_output_html($input)) {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

292)         logger(LOG_WARNING, 'inc/security', 'check_path', 'HTML-Krams im Pfad: ' . $input);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

293)         DEBUG("HTML-Krams im Pfad");
294)         return false;
295)     }
296)     $components = explode("/", $input);
297)     foreach ($components as $item) {
298)         if ($item == '..') {
Hanno Böck Spaces between string conca...

Hanno Böck authored 6 months ago

299)             logger(LOG_WARNING, 'inc/security', 'check_path', '»..« im Pfad: ' . $input);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

300)             DEBUG("»..« im Pfad");
301)             return false;
302)         }
Hanno prevent breaking kvhostcrea...

Hanno authored 5 years ago

303)         if (strlen($item) > 255) {
304)             return false;
305)         }
306)     }
307)     if (strlen($input) > 2048) {
308)         return false;
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

309)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

310)     return (preg_match('/^[ A-Za-z0-9.@\/_-]*$/', $input) == 1);
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

311) }
312) 
313) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

314) function in_homedir($path)
315) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

316)     DEBUG("Prüfe »{$path}«");
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

317)     if (!check_path($path)) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

318)         DEBUG('Kein Pfad');
319)         return false;
320)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 6 months ago

321)     if (!isset($_SESSION['userinfo']['homedir'])) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

322)         DEBUG("Kann homedir nicht ermitteln");
323)         return false;
324)     }
Bernd Wurst Syntaxfehler

Bernd Wurst authored 5 years ago

325)     return strncmp($_SESSION['userinfo']['homedir'], $path, strlen($_SESSION['userinfo']['homedir'])) == 0;
bernd * alle internen Links sinnv...

bernd authored 15 years ago

326) }
327) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

328) function check_date($input)
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

329) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

330)     return (bool) preg_match("/[0-9]{4}-(0?[1-9]|10|11|12)-([012]?[0-9]|30|31)/", $input);
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

331) }
332) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

333) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

334) function check_emailaddr($input)
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

335) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

336)     return (bool) filter_var($input, FILTER_VALIDATE_EMAIL) == $input;
bernd don't be too complicated. /...

bernd authored 16 years ago

337) }
338) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

339) function check_domain($input)
bernd don't be too complicated. /...

bernd authored 16 years ago

340) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

341)     return (bool) preg_match("/^[a-z0-9\.\-]+\.[a-z\-]{2,63}$/i", $input);
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

342) }
Hanno Böck Add function to check input...

Hanno Böck authored 3 years ago

343) 
344) function check_input_types($input, $types)
345) {
346)     foreach ($types as $key => $type) {
347)         if (!array_key_exists($key, $input)) {
348)             system_failure("Interner Fehler bei Eingabevariablen");
349)         }
350)         if ($type === 'int') {
Hanno Böck codingstyle - spaces with c...

Hanno Böck authored 3 months ago

351)             if ($input[$key] !== (string) (int) $input[$key]) {