Skip to content

Fix DSN construction vulnerable to special characters in password #18

Description

@PeaStew

Summary

The database DSN in hot_storage/sample/db.go is constructed via fmt.Sprintf:

dsn := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s", user, password, host, port, name, sslmode)

If DB_PASS contains URL-reserved characters (@, :, /, ?, #), the connection string breaks or is misinterpreted.

Affected Files

  • hot_storage/sample/db.go

Recommendation

Use net/url package for proper URL encoding:

u := &url.URL{
    Scheme:   "postgres",
    User:     url.UserPassword(user, password),
    Host:     fmt.Sprintf("%s:%s", host, port),
    Path:     name,
    RawQuery: fmt.Sprintf("sslmode=%s", sslmode),
}
dsn := u.String()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: lowLow severity findingsecuritySecurity issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions