Skip to content

fix(cors): allow cross-origin API calls only from configured origins - #42

Merged
danilovid merged 2 commits into
mainfrom
hotfix/cors-allowed-origins
Aug 28, 2026
Merged

fix(cors): allow cross-origin API calls only from configured origins#42
danilovid merged 2 commits into
mainfrom
hotfix/cors-allowed-origins

Conversation

@danilovid

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread lib/config/util.go Outdated
}

// SplitList turns a comma separated setting into a list, dropping empty entries and whitespace.
func SplitList(value string) []string {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of having such utility func we can add a new type implementing flag.Value (see docs) to this package

it can be something like:

type StringList []string

func (l *StringList) String() string {
	return strings.Join(*l, ",")
}

func (l *StringList) Set(v string) error {
	for _, s := range strings.Split(v, ",") {
		if s = strings.TrimSpace(s); s != "" {
			*l = append(*l, s)
		}
	}
	return nil
}

there's a generic version as well, but imo it's too complicated, since we should explicitly pass a parsing function:

Example
type List[T any] struct {
	Values []T
	Parse  func(string) (T, error)
}

func (l *List[T]) String() string {
	if l == nil || len(l.Values) == 0 {
		return ""
	}
	parts := make([]string, len(l.Values))
	for i, v := range l.Values {
		parts[i] = fmt.Sprint(v)
	}
	return strings.Join(parts, ",")
}

func (l *List[T]) Set(s string) error {
	for _, raw := range strings.Split(s, ",") {
		v, err := l.Parse(strings.TrimSpace(raw))
		if err != nil {
			return fmt.Errorf("incorrect value %q: %w", raw, err)
		}
		l.Values = append(l.Values, v)
	}
	return nil
}

@danilovid
danilovid force-pushed the hotfix/cors-allowed-origins branch 2 times, most recently from fd79adf to 0eec5cd Compare August 28, 2026 10:09
@danilovid
danilovid force-pushed the hotfix/cors-allowed-origins branch from 0eec5cd to 330aaef Compare August 28, 2026 10:14
@danilovid
danilovid merged commit 774ccfb into main Aug 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants