2df334d22ff62faf3549b0d5e67d2ab8bea2411e
bernd input-filtering

bernd authored 18 years ago

1) <?php
Hanno Böck Add newlines before comment...

Hanno Böck authored 1 year ago

2) 
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 14 years ago

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

Hanno Böck authored 3 years ago

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

Bernd Wurst authored 14 years ago

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

Hanno Böck authored 3 years ago

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

Bernd Wurst authored 14 years ago

11) 
12) 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.
13) */
bernd input-filtering

bernd authored 18 years ago

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

bernd authored 18 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 9 years ago

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

bernd authored 18 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 4 years ago

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

bernd authored 18 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 7 years ago

71)         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 7 years ago

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

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 5 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 7 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

bernd authored 18 years ago

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

Bernd Wurst authored 6 years ago

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

bernd authored 18 years ago

104) {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 7 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 7 years ago

113)     }
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 6 years ago

114)     return $filtered;
bernd input-filtering

bernd authored 18 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 4 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno Böck authored 2 years ago

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

Bernd Wurst authored 6 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

155) {
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 6 years ago

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

Hanno authored 7 years ago

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

hanno authored 18 years ago

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

Hanno authored 7 years ago

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

hanno authored 18 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

bernd authored 18 years ago

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

Hanno Böck authored 2 years ago

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

bernd authored 18 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 7 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno authored 7 years ago

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

Hanno authored 7 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno Böck authored 2 years ago

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

bernd authored 17 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 7 years ago

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

bernd authored 17 years ago

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

Hanno Böck authored 7 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 7 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 7 years ago

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

Hanno authored 7 years ago

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

bernd authored 17 years ago

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

Hanno Böck authored 2 years ago

220)     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 7 years ago

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

bernd authored 17 years ago

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

Hanno authored 7 years ago

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

bernd authored 17 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 2 years ago

229)     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 7 years ago

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

bernd authored 17 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 9 years ago

235) {
Bernd Wurst warnings vermeiden

Bernd Wurst authored 1 year ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 9 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

258) }
bernd input-filtering

bernd authored 18 years ago

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

bernd authored 18 years ago

260) 
Hanno Böck Optionaler Parameter für fi...

Hanno Böck authored 11 months ago

261) function filter_ssh_key($key, &$fphash = "")
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 9 years ago

262) {
Hanno Böck Einheitlicher, ausführliche...

Hanno Böck authored 11 months ago

263)     $filtered = trim(str_replace(["\r", "\n"], ' ', $key));
264)     $keyparts = explode(" ", $filtered);
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 9 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 9 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 9 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 9 years ago

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

Hanno Böck authored 5 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 9 years ago

281) 
Hanno Böck Sicherstellen dass in DynDN...

Hanno Böck authored 11 months ago

282)     if ($keyparts[0] == "ssh-dss") {
283)         system_failure("DSA-Keys werden nicht unterstützt!");
284)     }
285) 
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

286)     if (count($keyparts) === 2) {
Hanno Böck Einheitlicher, ausführliche...

Hanno Böck authored 11 months ago

287)         $fkey = $keyparts[0] . " " . $keyparts[1];
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

288)     } else {
Hanno Böck Einheitlicher, ausführliche...

Hanno Böck authored 11 months ago

289)         $fkey = $keyparts[0] . " " . $keyparts[1] . " " . $keyparts[2];
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

290)     }
Hanno Böck Einheitlicher, ausführliche...

Hanno Böck authored 11 months ago

291) 
Hanno Böck Bei proc_open sollte stdout...

Hanno Böck authored 11 months ago

292)     $descr = [
293)         0 => ["pipe", "r"],
294)         1 => ["pipe", "w"],
295)         2 => ["pipe", "w"],
296)     ];
297)     $sshcmd = proc_open("ssh-keygen -l -f -", $descr, $pipes, null, null);
Hanno Böck Einheitlicher, ausführliche...

Hanno Böck authored 11 months ago

298)     fwrite($pipes[0], $fkey);
Hanno Böck Optionaler Parameter für fi...

Hanno Böck authored 11 months ago

299)     fclose($pipes[0]);
300)     $fphash = fread($pipes[1], 1024);
Hanno Böck Einheitlicher, ausführliche...

Hanno Böck authored 11 months ago

301)     if (proc_close($sshcmd) !== 0) {
302)         system_failure("Ungültiger SSH-Key laut ssh-keygen!");
303)     }
304) 
Hanno Böck Optionaler Parameter für fi...

Hanno Böck authored 11 months ago

305)     $fphash = explode(" ", $fphash)[1];
306)     if ((strlen($fphash) != 50) || (substr($fphash, 0, 7) != "SHA256:")) {
307)         system_failure("Interner Fehler: Fingerprint im falschen Format");
308)     }
309)     $fphash = substr($fphash, 7);
310) 
Hanno Böck Einheitlicher, ausführliche...

Hanno Böck authored 11 months ago

311)     return $fkey;
Hanno Böck validiere SSH-Keys korrekt

Hanno Böck authored 9 years ago

312) }
313) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

Bernd Wurst authored 6 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 7 years ago

320)         DEBUG("HTML-Krams im Pfad");
321)         return false;
322)     }
323)     $components = explode("/", $input);
324)     foreach ($components as $item) {
325)         if ($item == '..') {
Hanno Böck Spaces between string conca...

Hanno Böck authored 2 years ago

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

Hanno authored 7 years ago

327)             DEBUG("»..« im Pfad");
328)             return false;
329)         }
Hanno prevent breaking kvhostcrea...

Hanno authored 7 years ago

330)         if (strlen($item) > 255) {
331)             return false;
332)         }
333)     }
334)     if (strlen($input) > 2048) {
335)         return false;
bernd XSS/CSRF-Bugs behoben

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

338) }
339) 
340) 
bernd * alle internen Links sinnv...

bernd authored 17 years ago

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

Hanno authored 7 years ago

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

Hanno Böck authored 2 years ago

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

Hanno authored 7 years ago

345)         DEBUG('Kein Pfad');
346)         return false;
347)     }
Hanno Böck Fix not operator (!) spaces

Hanno Böck authored 2 years ago

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

Hanno authored 7 years ago

349)         DEBUG("Kann homedir nicht ermitteln");
350)         return false;
351)     }
Bernd Wurst Syntaxfehler

Bernd Wurst authored 7 years ago

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

bernd authored 17 years ago

353) }
354) 
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

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

Bernd Wurst authored 12 years ago

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

Hanno authored 7 years ago

357)     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 12 years ago

358) }
359) 
bernd * alle internen Links sinnv...

bernd authored 17 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

364) }
365) 
Hanno Fix coding style with php-c...

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno authored 7 years ago

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

bernd authored 18 years ago

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

Hanno Böck authored 5 years ago

370) 
371) function check_input_types($input, $types)
372) {
373)     foreach ($types as $key => $type) {
374)         if (!array_key_exists($key, $input)) {
375)             system_failure("Interner Fehler bei Eingabevariablen");
376)         }
377)         if ($type === 'int') {
Hanno Böck codingstyle - spaces with c...

Hanno Böck authored 2 years ago

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