Skip to content

Commit 3db9207

Browse files
committed
fix: correct import ordering and validate NITRIC_HOSTNAME
- Move env import to correct alphabetical position (between batch and gateway) - Reject NITRIC_HOSTNAME values containing URL-unsafe characters (/?#, newlines, whitespace) at startup to prevent malformed URLs
1 parent c44b87f commit 3db9207

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/cloud/cloud.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/nitrictech/cli/pkg/cloud/apis"
2929
"github.com/nitrictech/cli/pkg/cloud/batch"
30+
"github.com/nitrictech/cli/pkg/cloud/env"
3031
"github.com/nitrictech/cli/pkg/cloud/gateway"
3132
"github.com/nitrictech/cli/pkg/cloud/http"
3233
"github.com/nitrictech/cli/pkg/cloud/keyvalue"
@@ -36,7 +37,6 @@ import (
3637
"github.com/nitrictech/cli/pkg/cloud/secrets"
3738
"github.com/nitrictech/cli/pkg/cloud/sql"
3839
"github.com/nitrictech/cli/pkg/cloud/storage"
39-
"github.com/nitrictech/cli/pkg/cloud/env"
4040
"github.com/nitrictech/cli/pkg/cloud/topics"
4141
"github.com/nitrictech/cli/pkg/cloud/websites"
4242
"github.com/nitrictech/cli/pkg/cloud/websockets"
@@ -259,6 +259,11 @@ type LocalCloudOptions struct {
259259
func New(projectName string, opts LocalCloudOptions) (*LocalCloud, error) {
260260
hostname := env.NITRIC_HOSTNAME.String()
261261

262+
// Reject hostnames containing characters that would produce malformed URLs
263+
if strings.ContainsAny(hostname, "/?#\r\n \t") {
264+
return nil, fmt.Errorf("NITRIC_HOSTNAME contains invalid characters: %q", hostname)
265+
}
266+
262267
// Bracket IPv6 literals for use in URLs (RFC 3986)
263268
if strings.Contains(hostname, ":") && !strings.HasPrefix(hostname, "[") {
264269
hostname = "[" + hostname + "]"

0 commit comments

Comments
 (0)