Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion api/internal/transport/api/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ func (h *Handler) ExportAliases(c *fiber.Ctx) error {
return c.SendString(b.String())
}

// isOwnDomain reports whether domain exactly matches one of the comma-separated
// service domains, case-insensitively. Unlike strings.Contains, it doesn't match
// substrings (e.g. "vpn.net" inside "ivpn.net") and ignores casing differences.
func isOwnDomain(domains string, domain string) bool {
for _, d := range strings.Split(domains, ",") {
if strings.EqualFold(strings.TrimSpace(d), domain) {
return true
}
}

return false
}

// resolveDomain resolves an AliasReq-style domain value - either a plain built-in domain
// name or a custom domain's UUID - to its FQDN. ok is false if domainParam doesn't resolve
// to a valid domain accessible to userID.
Expand All @@ -292,7 +305,7 @@ func (h *Handler) resolveDomain(ctx context.Context, userID string, domainParam
return fqdn.Name, true, true
}

if !strings.Contains(h.Cfg.Domains, domain) {
if !isOwnDomain(h.Cfg.Domains, domain) {
return "", false, false
}

Expand Down
4 changes: 2 additions & 2 deletions api/internal/transport/api/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func (h *Handler) PostRecipient(c *fiber.Ctx) error {
})
}

domain := strings.Split(req.Email, "@")
if strings.Contains(h.Cfg.Domains, domain[1]) {
parts := strings.Split(req.Email, "@")
if isOwnDomain(h.Cfg.Domains, parts[len(parts)-1]) {
return c.Status(400).JSON(fiber.Map{
"error": ErrInvalidDomain,
})
Expand Down