diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-12 09:50:00 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-12 09:50:00 +0200 |
| commit | a310aada1147da1b8aebb30ca3cbfab1dcf699de (patch) | |
| tree | 76d8d2dad2799d3f6d6195b586c61b0122b43759 /internal/util/util.go | |
| parent | 987876b1c6e7bee0f3b6996731e47188bcfe10a9 (diff) | |
Util: ReplaceWAYF ensure that the template is valid
Diffstat (limited to 'internal/util/util.go')
| -rw-r--r-- | internal/util/util.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/util/util.go b/internal/util/util.go index 6dad4b1..b104476 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -62,11 +62,23 @@ func WAYFEncode(input string) string { // See https://github.com/eduvpn/documentation/blob/dc4d53c47dd7a69e95d6650eec408e16eaa814a2/SERVER_DISCOVERY_SKIP_WAYF.md func ReplaceWAYF(authTemplate string, authURL string, orgID string) string { + // We just return the authURL in the cases where the template is not given or is invalid if authTemplate == "" { return authURL } + if !strings.Contains(authTemplate, "@RETURN_TO@") { + return authURL + } + if !strings.Contains(authTemplate, "@ORG_ID@") { + return authURL + } // Replace authURL authTemplate = strings.Replace(authTemplate, "@RETURN_TO@", WAYFEncode(authURL), 1) + + // If now there is no more ORG_ID, return as there weren't enough @ symbols + if !strings.Contains(authTemplate, "@ORG_ID@") { + return authURL + } // Replace ORG ID authTemplate = strings.Replace(authTemplate, "@ORG_ID@", WAYFEncode(orgID), 1) return authTemplate |
