28cd1b25e41b777a2c0e7afa623603fd1eff555a
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 Erlaube underscore in hostn...

Bernd Wurst authored 9 years ago

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

bernd authored 16 years ago

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

bernd authored 13 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

83)   return $input;
bernd check auf hostname

bernd authored 16 years ago

84) }
85) 
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 15 years ago

87) {
bernd Erlaube * im Hostname

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 16 years ago

108) 
109) 
bernd Im Passwort dürfen auch kei...

bernd authored 16 years ago

110) function filter_quotes( $input )
111) {
bernd deprecation of ereg* functi...

bernd authored 14 years ago

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

bernd authored 16 years ago

113) }
114) 
bernd Umfangreiche Code-Aufräumar...

bernd authored 16 years ago

115) 
116) 
bernd Diverse shell-kritische zei...

bernd authored 16 years ago

117) function filter_shell( $input )
118) {
bernd deprecation of ereg* functi...

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

126) }
bernd input-filtering

bernd authored 16 years ago

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

bernd authored 16 years ago

128) 
129) 
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

134)   {
bernd Logger mit Logleveln

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

138)   }
bernd XSS/CSRF-Bugs behoben

bernd authored 16 years ago

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

bernd authored 14 years ago

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

bernd authored 16 years ago

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

bernd authored 16 years ago

146)       return False;
147)     }
148)   }
bernd Erlaube Leerzeichen im Pfad

bernd authored 13 years ago

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

bernd authored 16 years ago

150) }
151) 
152) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

Bernd Wurst authored 9 years ago

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

172) }
173) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 16 years ago

175) function check_emailaddr( $input )
176) {
bernd Syntax-fehler

bernd authored 16 years ago

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

bernd authored 16 years ago

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