gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taldir] branch master updated: Payment Address validation with regex


From: gnunet
Subject: [taldir] branch master updated: Payment Address validation with regex
Date: Tue, 21 Jan 2025 22:52:41 +0100

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository taldir.

The following commit(s) were added to refs/heads/master by this push:
     new 7374d2b  Payment Address validation with regex
7374d2b is described below

commit 7374d2bd3cd6611649aa60227d6bc4366d98d91f
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Tue Jan 21 22:52:17 2025 +0100

    Payment Address validation with regex
---
 pkg/rest/taldir.go | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/pkg/rest/taldir.go b/pkg/rest/taldir.go
index 78f8cf8..b76022d 100644
--- a/pkg/rest/taldir.go
+++ b/pkg/rest/taldir.go
@@ -85,6 +85,9 @@ type Taldir struct {
        // The address salt
        Salt string
 
+       // Valid Payment System Address
+       ValidPMSRegex string
+
        // The timeframe for the validation requests
        ValidationTimeframe time.Duration
 
@@ -312,12 +315,22 @@ const monthDurationUs = 2592000000000
 // 1 Month as Go duration
 const monthDuration = time.Duration(monthDurationUs * 1000)
 
+func (t *Taldir) isPMSValid(pms string) (err error) {
+       if t.ValidPMSRegex != "" {
+               matched, _ := regexp.MatchString(t.ValidPMSRegex, pms)
+               if !matched {
+                       return errors.New(fmt.Sprintf("Payment System Address 
`%s' invalid", pms)) // TODO i18n
+               }
+       }
+       return
+}
+
 func (v *Validator) isAliasValid(alias string) (err error) {
        log.Println(v.ValidAliasRegex)
        if v.ValidAliasRegex != "" {
                matched, _ := regexp.MatchString(v.ValidAliasRegex, alias)
                if !matched {
-                       return errors.New(fmt.Sprintf("Alias '%s' invalid", 
alias)) // TODO i18n
+                       return errors.New(fmt.Sprintf("Alias `%s' invalid", 
alias)) // TODO i18n
                }
        }
        return
@@ -458,6 +471,12 @@ func (t *Taldir) registerRequest(w http.ResponseWriter, r 
*http.Request) {
                return
        }
 
+       err = t.isPMSValid(req.TargetUri)
+       if nil != err {
+               http.Redirect(w, r, fmt.Sprintf("/?error=%s", err), 
http.StatusSeeOther)
+               return
+       }
+
        // Setup validation object. Retrieve object from DB if it already
        // exists.
        h := sha512.New()
@@ -711,7 +730,7 @@ func (t *Taldir) methodLookupResultPage(w 
http.ResponseWriter, r *http.Request)
        alias := r.URL.Query().Get("address")
        err := val.isAliasValid(alias)
        if nil != err {
-               http.Redirect(w, r, fmt.Sprintf("?error=%s", err), 
http.StatusSeeOther)
+               http.Redirect(w, r, fmt.Sprintf("/?error=%s", err), 
http.StatusSeeOther)
                return
        }
        hAddressBin := sha512.Sum512([]byte(r.URL.Query().Get("address")))
@@ -851,6 +870,7 @@ func (t *Taldir) Initialize(cfgfile string, version string) 
{
        t.SolutionAttemptsMax = 
t.Cfg.Section("taldir").Key("solution_attempt_max").MustInt(3)
 
        validationTTLStr := 
t.Cfg.Section("taldir").Key("validation_timeframe").MustString("5m")
+       t.ValidPMSRegex = 
t.Cfg.Section("taldir").Key("valid_payment_system_address_regex").MustString("[A-Z]+")
        t.ValidationTimeframe, err = time.ParseDuration(validationTTLStr)
        if err != nil {
                log.Fatal(err)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]