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
18 changes: 9 additions & 9 deletions .github/workflows/ci-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: build-v2

on:
push:
branches:
tags:
branches: ["**"]
tags: ["**"]
paths:
- ".github/workflows/ci-v2.yml"
- "v2/**"
Expand All @@ -25,12 +25,12 @@ jobs:
sudo systemctl disable mono-xsp4.service || true

- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: set up go
uses: actions/setup-go@v6
with:
go-version: "1.25"
go-version: "1.26"
cache-dependency-path: v2/go.sum
id: go

Expand All @@ -48,23 +48,23 @@ jobs:

- name: build and test
run: |
go test -timeout=60s -v -race -p 1 -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov ./...
go test -timeout=60s -v -race -p 1 -covermode=atomic -coverprofile="$GITHUB_WORKSPACE/profile.cov" ./...
go build -race
working-directory: v2
env:
TZ: "America/Chicago"
ENABLE_MONGO_TESTS: "true"

- name: golangci-lint
uses: golangci/golangci-lint-action@v7
uses: golangci/golangci-lint-action@v9
with:
version: v2.6.2
args: --config ../.golangci.yml
version: v2.12.2
args: --config=../.golangci.yml
working-directory: v2

- name: submit coverage
run: |
go install github.com/mattn/goveralls@latest
goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov
goveralls -service="github" -coverprofile="$GITHUB_WORKSPACE/profile.cov"
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: build

on:
push:
branches:
tags:
branches: ["**"]
tags: ["**"]
paths-ignore:
- ".github/workflows/ci-v2.yml"
- "v2/**"
Expand All @@ -25,12 +25,12 @@ jobs:
sudo systemctl disable mono-xsp4.service || true

- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: set up go
uses: actions/setup-go@v6
with:
go-version: "1.25"
go-version: "1.26"
id: go

- name: launch mongodb
Expand All @@ -40,20 +40,20 @@ jobs:

- name: build and test
run: |
go test -timeout=60s -v -race -p 1 -covermode=atomic -coverprofile=$GITHUB_WORKSPACE/profile.cov ./...
go test -timeout=60s -v -race -p 1 -covermode=atomic -coverprofile="$GITHUB_WORKSPACE/profile.cov" ./...
go build -race
env:
TZ: "America/Chicago"
ENABLE_MONGO_TESTS: "true"

- name: golangci-lint
uses: golangci/golangci-lint-action@v7
uses: golangci/golangci-lint-action@v9
with:
version: v2.6.2
version: v2.12.2

- name: submit coverage
run: |
go install github.com/mattn/goveralls@latest
goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov
goveralls -service="github" -coverprofile="$GITHUB_WORKSPACE/profile.cov"
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v7

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -53,4 +53,4 @@ jobs:
TZ: "America/Chicago"

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
uses: github/codeql-action/analyze@v4
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ linters:
- linters:
- errcheck
path: _test\.go$
- linters:
- gosec
path: _test\.go$
- path: (.+)\.go$
text: should have a package comment, unless it's in another file for this package
- path: (.+)\.go$
Expand Down
18 changes: 9 additions & 9 deletions avatar/avatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,15 @@ func TestEtagMatches(t *testing.T) {
header string
want bool
}{
{etag, true}, // exact match — what browsers send
{`W/"abc123"`, true}, // weak validator
{`"other", "abc123"`, true}, // comma-separated, second matches
{` "abc123" `, true}, // leading/trailing whitespace
{`*`, true}, // wildcard matches anything
{`"abc"`, false}, // different etag
{`"abc123x"`, false}, // substring shouldn't match
{``, false}, // empty
{`abc123`, false}, // unquoted — invalid per RFC, must not match
{etag, true}, // exact match — what browsers send
{`W/"abc123"`, true}, // weak validator
{`"other", "abc123"`, true}, // comma-separated, second matches
{` "abc123" `, true}, // leading/trailing whitespace
{`*`, true}, // wildcard matches anything
{`"abc"`, false}, // different etag
{`"abc123x"`, false}, // substring shouldn't match
{``, false}, // empty
{`abc123`, false}, // unquoted — invalid per RFC, must not match
}
for _, tt := range tbl {
t.Run(tt.header, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion avatar/localfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (fs *LocalFS) Get(avatar string) (reader io.ReadCloser, size int, err error
func (fs *LocalFS) ID(avatar string) (id string) {
location := fs.location(strings.TrimSuffix(avatar, imgSfx))
avFile := path.Join(location, avatar)
fi, err := os.Stat(avFile)
fi, err := os.Stat(avFile) //nolint:gosec // avatar id is store-generated and validated by the proxy handler
if err != nil {
return encodeID(avatar)
}
Expand Down
2 changes: 1 addition & 1 deletion provider/apple.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (ah *AppleHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
}
ah.Logf("[DEBUG] login url %s, claims=%+v", loginURL, claims)

http.Redirect(w, r, loginURL, http.StatusFound)
http.Redirect(w, r, loginURL, http.StatusFound) //nolint:gosec // redirect goes to the fixed apple auth endpoint, request path only affects redirect_uri query param
}

// AuthHandler fills user info and redirects to "from" url. This is callback url redirected locally by browser
Expand Down
3 changes: 2 additions & 1 deletion provider/custom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func (c *CustomServer) handleAvatar(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
return
}
if _, err = w.Write(b); err != nil {
w.Header().Set("Content-Type", "image/png")
if _, err = w.Write(b); err != nil { //nolint:gosec // generated identicon png, not reflected markup
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
3 changes: 2 additions & 1 deletion provider/dev_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func (d *DevAuthServer) Run(ctx context.Context) { // nolint (gocyclo)
w.WriteHeader(http.StatusNotFound)
return
}
if _, err = w.Write(b); err != nil {
w.Header().Set("Content-Type", "image/png")
if _, err = w.Write(b); err != nil { //nolint:gosec // generated identicon png, not reflected markup
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
6 changes: 3 additions & 3 deletions provider/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func NewTwitter(p Params) Oauth1Handler {
func NewBattlenet(p Params) Oauth2Handler {
return initOauth2Handler(p, Oauth2Handler{
name: "battlenet",
endpoint: oauth2.Endpoint{
endpoint: oauth2.Endpoint{ //nolint:gosec // G101 false positive, oauth endpoint urls are not credentials
AuthURL: "https://eu.battle.net/oauth/authorize",
TokenURL: "https://eu.battle.net/oauth/token",
AuthStyle: oauth2.AuthStyleInParams,
Expand Down Expand Up @@ -241,7 +241,7 @@ func NewPatreon(p Params) Oauth2Handler {
return initOauth2Handler(p, Oauth2Handler{
name: "patreon",
// see https://docs.patreon.com/?shell#oauth
endpoint: oauth2.Endpoint{
endpoint: oauth2.Endpoint{ //nolint:gosec // G101 false positive, oauth endpoint urls are not credentials
AuthURL: "https://www.patreon.com/oauth2/authorize",
TokenURL: "https://api.patreon.com/oauth2/token",
AuthStyle: oauth2.AuthStyleInParams,
Expand Down Expand Up @@ -276,7 +276,7 @@ func NewDiscord(p Params) Oauth2Handler {
return initOauth2Handler(p, Oauth2Handler{
name: "discord",
// see https://discord.com/developers/docs/topics/oauth2
endpoint: oauth2.Endpoint{
endpoint: oauth2.Endpoint{ //nolint:gosec // G101 false positive, oauth endpoint urls are not credentials
AuthURL: "https://discord.com/oauth2/authorize",
TokenURL: "https://discord.com/api/oauth2/token",
},
Expand Down
8 changes: 4 additions & 4 deletions token/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ func (j *Service) Set(w http.ResponseWriter, claims Claims) (Claims, error) {
cookieExpiration = int(j.CookieDuration.Seconds())
}

jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: tokenString, HttpOnly: true, Path: "/", Domain: j.JWTCookieDomain,
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: tokenString, HttpOnly: true, Path: "/", Domain: j.JWTCookieDomain, //nolint:gosec // Secure and SameSite come from service config
MaxAge: cookieExpiration, Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &jwtCookie)

xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: claims.Id, HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain,
xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: claims.Id, HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain, //nolint:gosec // HttpOnly false by design, JS reads it for the X-XSRF-Token header
MaxAge: cookieExpiration, Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &xsrfCookie)

Expand Down Expand Up @@ -335,11 +335,11 @@ func (j *Service) IsExpired(claims Claims) bool {

// Reset token's cookies
func (j *Service) Reset(w http.ResponseWriter) {
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain,
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain, //nolint:gosec // expired removal cookie, carries no value
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &jwtCookie)

xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain,
xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain, //nolint:gosec // expired removal cookie, carries no value
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &xsrfCookie)

Expand Down
18 changes: 9 additions & 9 deletions v2/avatar/avatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,15 @@ func TestEtagMatches(t *testing.T) {
header string
want bool
}{
{etag, true}, // exact match — what browsers send
{`W/"abc123"`, true}, // weak validator
{`"other", "abc123"`, true}, // comma-separated, second matches
{` "abc123" `, true}, // leading/trailing whitespace
{`*`, true}, // wildcard matches anything
{`"abc"`, false}, // different etag
{`"abc123x"`, false}, // substring shouldn't match
{``, false}, // empty
{`abc123`, false}, // unquoted — invalid per RFC, must not match
{etag, true}, // exact match — what browsers send
{`W/"abc123"`, true}, // weak validator
{`"other", "abc123"`, true}, // comma-separated, second matches
{` "abc123" `, true}, // leading/trailing whitespace
{`*`, true}, // wildcard matches anything
{`"abc"`, false}, // different etag
{`"abc123x"`, false}, // substring shouldn't match
{``, false}, // empty
{`abc123`, false}, // unquoted — invalid per RFC, must not match
}
for _, tt := range tbl {
t.Run(tt.header, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion v2/avatar/localfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (fs *LocalFS) Get(avatar string) (reader io.ReadCloser, size int, err error
func (fs *LocalFS) ID(avatar string) (id string) {
location := fs.location(strings.TrimSuffix(avatar, imgSfx))
avFile := path.Join(location, avatar)
fi, err := os.Stat(avFile)
fi, err := os.Stat(avFile) //nolint:gosec // avatar id is store-generated and validated by the proxy handler
if err != nil {
return encodeID(avatar)
}
Expand Down
2 changes: 1 addition & 1 deletion v2/provider/apple.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (ah *AppleHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
}
ah.Logf("[DEBUG] login url %s, claims=%+v", loginURL, claims)

http.Redirect(w, r, loginURL, http.StatusFound)
http.Redirect(w, r, loginURL, http.StatusFound) //nolint:gosec // redirect goes to the fixed apple auth endpoint, request path only affects redirect_uri query param
}

// AuthHandler fills user info and redirects to "from" url. This is callback url redirected locally by browser
Expand Down
3 changes: 2 additions & 1 deletion v2/provider/custom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func (c *CustomServer) handleAvatar(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
return
}
if _, err = w.Write(b); err != nil {
w.Header().Set("Content-Type", "image/png")
if _, err = w.Write(b); err != nil { //nolint:gosec // generated identicon png, not reflected markup
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
3 changes: 2 additions & 1 deletion v2/provider/dev_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func (d *DevAuthServer) Run(ctx context.Context) { // nolint (gocyclo)
w.WriteHeader(http.StatusNotFound)
return
}
if _, err = w.Write(b); err != nil {
w.Header().Set("Content-Type", "image/png")
if _, err = w.Write(b); err != nil { //nolint:gosec // generated identicon png, not reflected markup
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
6 changes: 3 additions & 3 deletions v2/provider/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func NewTwitter(p Params) Oauth1Handler {
func NewBattlenet(p Params) Oauth2Handler {
return initOauth2Handler(p, Oauth2Handler{
name: "battlenet",
endpoint: oauth2.Endpoint{
endpoint: oauth2.Endpoint{ //nolint:gosec // G101 false positive, oauth endpoint urls are not credentials
AuthURL: "https://eu.battle.net/oauth/authorize",
TokenURL: "https://eu.battle.net/oauth/token",
AuthStyle: oauth2.AuthStyleInParams,
Expand Down Expand Up @@ -241,7 +241,7 @@ func NewPatreon(p Params) Oauth2Handler {
return initOauth2Handler(p, Oauth2Handler{
name: "patreon",
// see https://docs.patreon.com/?shell#oauth
endpoint: oauth2.Endpoint{
endpoint: oauth2.Endpoint{ //nolint:gosec // G101 false positive, oauth endpoint urls are not credentials
AuthURL: "https://www.patreon.com/oauth2/authorize",
TokenURL: "https://api.patreon.com/oauth2/token",
AuthStyle: oauth2.AuthStyleInParams,
Expand Down Expand Up @@ -276,7 +276,7 @@ func NewDiscord(p Params) Oauth2Handler {
return initOauth2Handler(p, Oauth2Handler{
name: "discord",
// see https://discord.com/developers/docs/topics/oauth2
endpoint: oauth2.Endpoint{
endpoint: oauth2.Endpoint{ //nolint:gosec // G101 false positive, oauth endpoint urls are not credentials
AuthURL: "https://discord.com/oauth2/authorize",
TokenURL: "https://discord.com/api/oauth2/token",
},
Expand Down
8 changes: 4 additions & 4 deletions v2/token/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ func (j *Service) Set(w http.ResponseWriter, claims Claims) (Claims, error) {
cookieExpiration = int(j.CookieDuration.Seconds())
}

jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: tokenString, HttpOnly: true, Path: "/", Domain: j.JWTCookieDomain,
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: tokenString, HttpOnly: true, Path: "/", Domain: j.JWTCookieDomain, //nolint:gosec // Secure and SameSite come from service config
MaxAge: cookieExpiration, Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &jwtCookie)

xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: claims.ID, HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain,
xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: claims.ID, HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain, //nolint:gosec // HttpOnly false by design, JS reads it for the X-XSRF-Token header
MaxAge: cookieExpiration, Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &xsrfCookie)

Expand Down Expand Up @@ -357,11 +357,11 @@ func (j *Service) IsExpired(claims Claims) bool {

// Reset token's cookies
func (j *Service) Reset(w http.ResponseWriter) {
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain,
jwtCookie := http.Cookie{Name: j.JWTCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain, //nolint:gosec // expired removal cookie, carries no value
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &jwtCookie)

xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain,
xsrfCookie := http.Cookie{Name: j.XSRFCookieName, Value: "", HttpOnly: false, Path: "/", Domain: j.JWTCookieDomain, //nolint:gosec // expired removal cookie, carries no value
MaxAge: -1, Expires: time.Unix(0, 0), Secure: j.SecureCookies, SameSite: j.SameSite}
http.SetCookie(w, &xsrfCookie)

Expand Down
Loading