[10/10] importer: Validate country codes from Geofeeds

Message ID 20220927164847.3409646-10-michael.tremer@ipfire.org
State Accepted
Commit 72908243332d06713a93d9f7c5019c11097b3d33
Headers
Series [01/10] importer: Store geofeed URLs from RIR data |

Commit Message

Michael Tremer Sept. 27, 2022, 4:48 p.m. UTC
  Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 src/scripts/location-importer.in | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
  

Patch

diff --git a/src/scripts/location-importer.in b/src/scripts/location-importer.in
index d0384b5..d8f9cbf 100644
--- a/src/scripts/location-importer.in
+++ b/src/scripts/location-importer.in
@@ -1421,7 +1421,15 @@  class CLI(object):
 							log.debug("Could not parse network: %s" % network)
 							continue
 
-						# XXX Check the country code
+						# Strip any excess whitespace from country codes
+						if country:
+							country = country.strip()
+
+						# Check the country code
+						if not location.country_code_is_valid(country):
+							log.warning("Invalid country code in Geofeed %s: %s" \
+								% (geofeed.url, country))
+							continue
 
 						# Write this into the database
 						self.db.execute("""