bbc3bcac38ffcf87fb8335c24737c562ccabc458
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) 
Bernd Wurst Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 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) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) 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.
15) */
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

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

Hanno Böck authored 7 years ago

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

bernd authored 16 years ago

19) 
bernd input-filtering

bernd authored 16 years ago

20) 
Hanno Böck replace cracklib with zxcvbn

Hanno Böck authored 7 years ago

21) function strong_password($password, $user = array())
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

22) {
Hanno Böck replace cracklib with zxcvbn

Hanno Böck authored 7 years ago

23)   $passwordchecker = new ZxcvbnPhp\Zxcvbn();
24)   $strength = $passwordchecker->passwordStrength($password, $user);
Bernd Wurst Subusers-Modul in einer ers...

Bernd Wurst authored 12 years ago

25) 
Hanno Böck replace cracklib with zxcvbn

Hanno Böck authored 7 years ago

26)   if ($strength['score'] < 2) {
27)     return "Das Passwort ist zu einfach!";
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

28)   }
29) 
Hanno Böck replace cracklib with zxcvbn

Hanno Böck authored 7 years ago

30)   return true;
bernd * Passwörter mit cracklib p...

bernd authored 16 years ago

31) }
32) 
33) 
bernd input-filtering

bernd authored 16 years ago

34) function filter_input_general( $input )
35) {
Bernd Wurst Weitere Prepared-Statements

Bernd Wurst authored 10 years ago

36)   if ($input === NULL) {
37)     return NULL;
38)   }
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

39)   return htmlspecialchars(iconv('UTF-8', 'UTF-8', $input), ENT_QUOTES, 'UTF-8');
40) }
41) 
42) 
43) function verify_input_general( $input )
44) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

45)   if (filter_input_general($input) != $input) {
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

46)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Logger mit Logleveln

bernd authored 14 years ago

47)     logger(LOG_WARNING, 'inc/security', 'verify_input_general', 'Ungültige Daten: '.$input);
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

48)   }
bernd input-filtering

bernd authored 16 years ago

49) }
50) 
51) 
52) function filter_input_username( $input )
53) {
bernd deprecation of ereg* functi...

bernd authored 14 years ago

54)   return preg_replace("/[^[:alnum:]\_\.\+\-]/", "", $input );
hanno Hatte die Kompatibilität ge...

hanno authored 16 years ago

55) }
56) 
57) function verify_input_username( $input )
58) {
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

59)   if (filter_input_username( $input ) != $input) {
bernd Logger mit Logleveln

bernd authored 14 years ago

60)     logger(LOG_WARNING, 'inc/security', 'verify_input_username', 'Ungültige Daten: '.$input);
bernd Add IP-address patterns

bernd authored 15 years ago

61)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Loggen, wenn ungültige Zeic...

bernd authored 16 years ago

62)   }
bernd input-filtering

bernd authored 16 years ago

63) }
64) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

65) 
66) 
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 16 years ago

68) {
bernd Erlaube * im Hostname

bernd authored 14 years ago

69)   // FIXME: Eine "filter"-Funktion sollte keinen system_failure verursachen sondern einfach einen bereinigten String liefern.
70)   
Bernd Wurst Wildcard-CSRs können jetzt...

Bernd Wurst authored 11 years ago

71)   DEBUG('filter_input_hostname("'.$input.'", $wildcard='.$wildcard.')');
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

72)   $input = str_replace(array('Ä', 'Ö', 'Ü'), array('ä', 'ö', 'ü'), strtolower($input));
bernd Hostnames sollten nicht mit...

bernd authored 16 years ago

73)   $input = rtrim($input, "\t\n\r\x00 .");
74)   $input = ltrim($input, "\t\n\r\x00 .");
Bernd Wurst Hostnames dürfen keine Unte...

Bernd Wurst authored 7 years ago

75)   if (preg_replace("/[^.]_/", "", $input) != $input) {
76)     system_failure("Der Unterstrich ist nur als erstes Zeichen eines Hostnames erlaubt.");
77)   }
Bernd Wurst Erlaube underscore in hostn...

Bernd Wurst authored 9 years ago

78)   if (preg_replace("/[^[:alnum:]äöü_*\.\-]/", "", $input ) != $input)
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

79)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Erlaube wildcards bei vhosts

bernd authored 13 years ago

80)   if (preg_match("/^.+\*/", $input ))
81)     system_failure("Ihre Daten enthielten ungültige Zeichen (Wildcard-Stern muss ganz vorne stehen)!");
82)   if (! $wildcard && preg_replace("/^\*/", "", $input ) != $input)
bernd Erlaube * im Hostname

bernd authored 14 years ago

83)     system_failure("Ihre Daten enthielten ungültige Zeichen (Keine Wildcards erlaubt)!");
bernd Hostname darf kein »..« ent...

bernd authored 16 years ago

84)   if (strstr($input, '..'))
85)     system_failure("Ungültiger Hostname");
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

86)   return $input;
bernd check auf hostname

bernd authored 16 years ago

87) }
88) 
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 15 years ago

90) {
bernd Erlaube * im Hostname

bernd authored 14 years ago

91)   if (filter_input_hostname( $input, $wildcard ) != $input) {
bernd Logger mit Logleveln

bernd authored 14 years ago

92)     logger(LOG_WARNING, 'inc/security', 'verify_input_hostname', 'Ungültige Daten: '.$input);
bernd Add IP-address patterns

bernd authored 15 years ago

93)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
94)   }
95) }
96) 
97) 
98) function verify_input_ipv4( $input )
99) {
100)   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))
101)     system_failure('Keine IP-Adresse');
102) }
103) 
104) 
105) function verify_input_ipv6( $input )
106) {
107)   // ripped from Perl module Net-IPv6Addr v0.2
108)   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))
109)     system_failure("Ungültige IPv6-Adresse");
110) }
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

111) 
112) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

113) function filter_quotes( $input )
114) {
bernd deprecation of ereg* functi...

bernd authored 14 years ago

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

bernd authored 16 years ago

116) }
117) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

118) 
119) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

120) function filter_shell( $input )
121) {
bernd deprecation of ereg* functi...

bernd authored 14 years ago

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

bernd authored 16 years ago

123) }
124) 
125) function verify_shell( $input )
126) {
127)   if (filter_shell($input) != $input)
128)     system_failure("Ihre Daten enthielten ungültige Zeichen!");
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

129) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

131) 
132) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

133) function check_path( $input )
134) {
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

135)   DEBUG("checking {$input} for valid path name");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

136)   if ($input != filter_input_general($input))
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

137)   {
bernd Logger mit Logleveln

bernd authored 14 years ago

138)     logger(LOG_WARNING, 'inc/security', 'check_path', 'HTML-Krams im Pfad: '.$input);
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

139)     DEBUG("HTML-Krams im Pfad");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

140)     return False;
bernd Auch @ darf im Mailbox-Pfad...

bernd authored 16 years ago

141)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

142)   $components = explode("/", $input);
143)   foreach ($components AS $item)
144)   {
145)     if ($item == '..')
146)     {
bernd Logger mit Logleveln

bernd authored 14 years ago

147)       logger(LOG_WARNING, 'inc/security', 'check_path', '»..« im Pfad: '.$input);
bernd check auf hostname

bernd authored 16 years ago

148)       DEBUG("»..« im Pfad");
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

149)       return False;
150)     }
151)   }
bernd Erlaube Leerzeichen im Pfad

bernd authored 13 years ago

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

bernd authored 16 years ago

153) }
154) 
155) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

156) function in_homedir($path)
157) {
158)   DEBUG("Prüfe »{$path}«");
159)   if (! check_path($path))
160)   {
161)     DEBUG('Kein Pfad');
162)     return False;
163)   }
164)   if (! isset($_SESSION['userinfo']['homedir']))
165)   {
166)     DEBUG("Kann homedir nicht ermitteln");
167)     return False;
168)   }
169)   return strncmp($_SESSION['userinfo']['homedir'], $path, count($_SESSION['userinfo']['homedir'])) == 0;
170) }
171) 
Bernd Wurst Erste Version des SEPA-Mand...

Bernd Wurst authored 10 years ago

172) function check_date( $input )
173) {
Bernd Wurst Erlaube beim SEPA-Mandat au...

Bernd Wurst authored 9 years ago

174)   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

175) }
176) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

177) 
bernd Neues Modul für "Kunde werden"

bernd authored 16 years ago

178) function check_emailaddr( $input )
179) {
bernd Syntax-fehler

bernd authored 16 years ago

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

bernd authored 16 years ago

181) }
182) 
183) function check_domain( $input )
184) {
185)   return (bool) preg_match("/[a-z0-9\.\-]+\.[a-z]{2,4}$/i", $input );