comparison urllog.tcl @ 572:295c225e3152

urllog: Improve invalid/local IPv4 network check
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 27 Sep 2020 14:56:48 +0300
parents d4d2fda12308
children d004944d6afd
comparison
equal deleted inserted replaced
571:d4d2fda12308 572:295c225e3152
259 } 259 }
260 260
261 ### Handle URLs that have an IPv4-address 261 ### Handle URLs that have an IPv4-address
262 if {[regexp "(\[a-z\]+)://(\[0-9\]{1,3})\\.(\[0-9\]{1,3})\\.(\[0-9\]{1,3})\\.(\[0-9\]{1,3})" $urlStr urlMatch urlProto ni1 ni2 ni3 ni4]} { 262 if {[regexp "(\[a-z\]+)://(\[0-9\]{1,3})\\.(\[0-9\]{1,3})\\.(\[0-9\]{1,3})\\.(\[0-9\]{1,3})" $urlStr urlMatch urlProto ni1 ni2 ni3 ni4]} {
263 # Check if the IP is on local network 263 # Check if the IP is on local network
264 if {$ni1 == 127 || $ni1 == 10 || ($ni1 == 192 && $ni2 == 168) || $ni1 == 0} { 264 if {$ni1 == 127 || $ni1 == 10 || ($ni1 == 192 && $ni2 == 168)} {
265 urllog_log "URL pointing to local or invalid network, ignored ($urlStr)." 265 urllog_log "URL pointing to local network, ignored ($urlStr)."
266 return 0 266 return 0
267 } 267 }
268 if {$ni1 >= 255 || $ni2 >= 255 || $ni3 >= 255 || $ni4 >= 255} { 268 if {$ni1 == 0 || $ni1 >= 255 || $ni2 >= 255 || $ni3 >= 255 || $ni4 >= 255} {
269 urllog_log "URL pointing to invalid network, ignored ($urlStr)." 269 urllog_log "URL pointing to invalid network, ignored ($urlStr)."
270 return 0 270 return 0
271 } 271 }
272 # Skip TLD check for URLs with IP address 272 # Skip TLD check for URLs with IP address
273 set u_checktld 0 273 set u_checktld 0