-
-
Notifications
You must be signed in to change notification settings - Fork 248
feat: do not show oidc consent screen every time #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package service | |
| import ( | ||
| "context" | ||
| "crypto" | ||
| "crypto/hmac" | ||
| "crypto/rand" | ||
| "crypto/rsa" | ||
| "crypto/sha256" | ||
|
|
@@ -22,6 +23,7 @@ import ( | |
|
|
||
| "github.com/go-jose/go-jose/v4" | ||
| "github.com/golang-jwt/jwt/v5" | ||
| "github.com/google/uuid" | ||
| "github.com/steveiliop56/ding" | ||
| "github.com/tinyauthapp/tinyauth/internal/model" | ||
| "github.com/tinyauthapp/tinyauth/internal/repository" | ||
|
|
@@ -305,6 +307,9 @@ func NewOIDCService(i OIDCServiceInput) (*OIDCService, error) { | |
|
|
||
| for id, client := range i.Config.OIDC.Clients { | ||
| client.ID = id | ||
| if err := uuid.Validate(client.ClientID); err != nil { | ||
| return nil, fmt.Errorf("invalid client id: %w", err) | ||
| } | ||
| if client.Name == "" { | ||
| client.Name = utils.Capitalize(client.ID) | ||
| } | ||
|
|
@@ -318,6 +323,9 @@ func NewOIDCService(i OIDCServiceInput) (*OIDCService, error) { | |
| client.ClientSecret = secret | ||
| } | ||
| client.ClientSecretFile = "" | ||
| if len(client.ClientSecret) < 32 { | ||
| return nil, fmt.Errorf("client secret for client %s is too short, must be >= 32 chars", client.ClientID) | ||
| } | ||
| clients[id] = client | ||
| i.Log.App.Debug().Str("clientId", client.ClientID).Msg("Loaded OIDC client configuration") | ||
| } | ||
|
|
@@ -969,3 +977,21 @@ func (service *OIDCService) GetPrompt(prompt string) []OIDCPrompt { | |
|
|
||
| return parsedPromps | ||
| } | ||
|
|
||
| func (service *OIDCService) CreateSignedValue(key string, data []byte) string { | ||
| // create the signature | ||
| h := hmac.New(sha256.New, []byte(key)) | ||
| h.Write(data) | ||
| sig := base64.URLEncoding.EncodeToString(h.Sum(nil)) | ||
|
|
||
| // hash the data | ||
| hasher := sha256.New() | ||
| hasher.Write(data) | ||
| hash := base64.URLEncoding.EncodeToString(hasher.Sum(nil)) | ||
|
|
||
| return fmt.Sprintf("%s.%s", hash, sig) | ||
| } | ||
|
|
||
| func (service *OIDCService) VerifySignedValue(key string, data []byte, signedValue string) bool { | ||
| return service.CreateSignedValue(key, data) == signedValue | ||
| } | ||
|
Comment on lines
+995
to
+997
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the relevant file and surrounding context.
sed -n '1,120p' internal/service/oidc_service.go
printf '\n----\n'
sed -n '940,1020p' internal/service/oidc_service.go
printf '\n----\n'
# Find related symbols/usages.
rg -n "VerifySignedValue|CreateSignedValue|hmac\.Equal|Verify.*Signed" internal/service/oidc_service.go internal -SRepository: tinyauthapp/tinyauth Length of output: 7359 Use constant-time comparison for the signature check. 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: tinyauthapp/tinyauth
Length of output: 20696
🏁 Script executed:
Repository: tinyauthapp/tinyauth
Length of output: 7322
🏁 Script executed:
Repository: tinyauthapp/tinyauth
Length of output: 8988
Bind consent to the authenticated user The scope cookie is browser-wide and not tied to the logged-in account, so a different user on the same browser can skip consent for the same client/scopes. It also survives logout because nothing clears it. Bind the signed value to the user identity (for example
sub) and clear it on logout.🤖 Prompt for AI Agents