]> gitweb.factorcode.org Git - factor.git/commitdiff
urls: adding redacted-url to mask the password of a URL.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 15 May 2020 19:11:29 +0000 (12:11 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 15 May 2020 19:13:00 +0000 (12:13 -0700)
This is particularly useful for logging to avoid accidentally printing
passwords in web server logs.

basis/urls/urls-docs.factor
basis/urls/urls-tests.factor
basis/urls/urls.factor

index 743723c71cbb9e258b31a95070deb2cc2fe0eee8..39a50b14252e50e9ffcc1b5f691d9939a7e627f6 100644 (file)
@@ -136,6 +136,10 @@ HELP: relative-url?
      { "?" boolean } }
 { $description "Tests whether a URL is relative." } ;
 
+HELP: redacted-url
+{ $values { "url" url } { "url'" url } }
+{ $description "Outputs a new URL with the password (if specified) replaced with " { $snippet "xxxxx" } ". This is useful for logging utilities where you want to avoid printing out the password in the logs." } ;
+
 HELP: secure-protocol?
 { $values { "protocol" string } { "?" boolean } }
 { $description "Tests if protocol connections must be made with secure sockets (SSL/TLS)." }
index b754de7086f09b353fca4c9e2e892316dae9394a..fb14e1ecba32f449fe23aa1bd695f9d16846d2ac 100644 (file)
@@ -325,3 +325,7 @@ urls [
 { URL" http://www.google.com/" } [
     URL" http://www.google.com/"
 ] unit-test
+
+{ URL" https://host:1234/path" } [ URL" https://host:1234/path" redacted-url ] unit-test
+{ URL" https://user@host:1234/path" } [ URL" https://user@host:1234/path" redacted-url ] unit-test
+{ URL" https://user:xxxxx@host:1234/path" } [ URL" https://user:password@host:1234/path" redacted-url ] unit-test
index ae444449a5b551879c931e59980aeabef1ddb0d7..7439b5d359519145da4a7e673afb60ff2e7c7f5b 100644 (file)
@@ -170,6 +170,9 @@ PRIVATE>
         [ [ anchor>>    ] either? >>anchor ]
     } 2cleave ;
 
+: redacted-url ( url -- url' )
+    clone [ "xxxxx" and ] change-password ;
+
 ! Half-baked stuff follows
 : secure-protocol? ( protocol -- ? )
     "https" = ;