mirror of
				https://github.com/h44z/wg-portal.git
				synced 2025-11-03 23:56:18 +00:00 
			
		
		
		
	fix: fix session handling (remove IdleTimeout)
This commit is contained in:
		@@ -125,7 +125,7 @@ router.beforeEach(async (to) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
router.afterEach(async (to, from) => {
 | 
					router.afterEach(async (to, from) => {
 | 
				
			||||||
  const sec = securityStore()
 | 
					  const sec = securityStore()
 | 
				
			||||||
  const csrfPages = ['/login']
 | 
					  const csrfPages = ['/', '/login']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (csrfPages.includes(to.path)) {
 | 
					  if (csrfPages.includes(to.path)) {
 | 
				
			||||||
    await sec.LoadSecurityProperties() // make sure we have a valid csrf token
 | 
					    await sec.LoadSecurityProperties() // make sure we have a valid csrf token
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,7 +58,7 @@
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        "/auth/logout": {
 | 
					        "/auth/logout": {
 | 
				
			||||||
            "get": {
 | 
					            "post": {
 | 
				
			||||||
                "produces": [
 | 
					                "produces": [
 | 
				
			||||||
                    "application/json"
 | 
					                    "application/json"
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
@@ -66,15 +66,12 @@
 | 
				
			|||||||
                    "Authentication"
 | 
					                    "Authentication"
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
                "summary": "Get all available external login providers.",
 | 
					                "summary": "Get all available external login providers.",
 | 
				
			||||||
                "operationId": "auth_handleLogoutGet",
 | 
					                "operationId": "auth_handleLogoutPost",
 | 
				
			||||||
                "responses": {
 | 
					                "responses": {
 | 
				
			||||||
                    "200": {
 | 
					                    "200": {
 | 
				
			||||||
                        "description": "OK",
 | 
					                        "description": "OK",
 | 
				
			||||||
                        "schema": {
 | 
					                        "schema": {
 | 
				
			||||||
                            "type": "array",
 | 
					                            "$ref": "#/definitions/model.Error"
 | 
				
			||||||
                            "items": {
 | 
					 | 
				
			||||||
                                "$ref": "#/definitions/model.LoginProviderInfo"
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -1523,23 +1520,23 @@
 | 
				
			|||||||
        "model.AuditEntry": {
 | 
					        "model.AuditEntry": {
 | 
				
			||||||
            "type": "object",
 | 
					            "type": "object",
 | 
				
			||||||
            "properties": {
 | 
					            "properties": {
 | 
				
			||||||
 | 
					                "ContextUser": {
 | 
				
			||||||
 | 
					                    "type": "string"
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                "Id": {
 | 
				
			||||||
 | 
					                    "type": "integer"
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
                "Message": {
 | 
					                "Message": {
 | 
				
			||||||
                    "type": "string"
 | 
					                    "type": "string"
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                "ctx_user": {
 | 
					                "Origin": {
 | 
				
			||||||
                    "type": "string"
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                "id": {
 | 
					 | 
				
			||||||
                    "type": "integer"
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                "origin": {
 | 
					 | 
				
			||||||
                    "description": "origin: for example user auth, stats, ...",
 | 
					                    "description": "origin: for example user auth, stats, ...",
 | 
				
			||||||
                    "type": "string"
 | 
					                    "type": "string"
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                "severity": {
 | 
					                "Severity": {
 | 
				
			||||||
                    "type": "string"
 | 
					                    "type": "string"
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                "timestamp": {
 | 
					                "Timestamp": {
 | 
				
			||||||
                    "type": "string"
 | 
					                    "type": "string"
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,18 +2,18 @@ basePath: /api/v0
 | 
				
			|||||||
definitions:
 | 
					definitions:
 | 
				
			||||||
  model.AuditEntry:
 | 
					  model.AuditEntry:
 | 
				
			||||||
    properties:
 | 
					    properties:
 | 
				
			||||||
 | 
					      ContextUser:
 | 
				
			||||||
 | 
					        type: string
 | 
				
			||||||
 | 
					      Id:
 | 
				
			||||||
 | 
					        type: integer
 | 
				
			||||||
      Message:
 | 
					      Message:
 | 
				
			||||||
        type: string
 | 
					        type: string
 | 
				
			||||||
      ctx_user:
 | 
					      Origin:
 | 
				
			||||||
        type: string
 | 
					 | 
				
			||||||
      id:
 | 
					 | 
				
			||||||
        type: integer
 | 
					 | 
				
			||||||
      origin:
 | 
					 | 
				
			||||||
        description: 'origin: for example user auth, stats, ...'
 | 
					        description: 'origin: for example user auth, stats, ...'
 | 
				
			||||||
        type: string
 | 
					        type: string
 | 
				
			||||||
      severity:
 | 
					      Severity:
 | 
				
			||||||
        type: string
 | 
					        type: string
 | 
				
			||||||
      timestamp:
 | 
					      Timestamp:
 | 
				
			||||||
        type: string
 | 
					        type: string
 | 
				
			||||||
    type: object
 | 
					    type: object
 | 
				
			||||||
  model.ConfigOption-array_string:
 | 
					  model.ConfigOption-array_string:
 | 
				
			||||||
@@ -496,17 +496,15 @@ paths:
 | 
				
			|||||||
      tags:
 | 
					      tags:
 | 
				
			||||||
      - Authentication
 | 
					      - Authentication
 | 
				
			||||||
  /auth/logout:
 | 
					  /auth/logout:
 | 
				
			||||||
    get:
 | 
					    post:
 | 
				
			||||||
      operationId: auth_handleLogoutGet
 | 
					      operationId: auth_handleLogoutPost
 | 
				
			||||||
      produces:
 | 
					      produces:
 | 
				
			||||||
      - application/json
 | 
					      - application/json
 | 
				
			||||||
      responses:
 | 
					      responses:
 | 
				
			||||||
        "200":
 | 
					        "200":
 | 
				
			||||||
          description: OK
 | 
					          description: OK
 | 
				
			||||||
          schema:
 | 
					          schema:
 | 
				
			||||||
            items:
 | 
					            $ref: '#/definitions/model.Error'
 | 
				
			||||||
              $ref: '#/definitions/model.LoginProviderInfo'
 | 
					 | 
				
			||||||
            type: array
 | 
					 | 
				
			||||||
      summary: Get all available external login providers.
 | 
					      summary: Get all available external login providers.
 | 
				
			||||||
      tags:
 | 
					      tags:
 | 
				
			||||||
      - Authentication
 | 
					      - Authentication
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,9 +57,11 @@ func NewRestApi(
 | 
				
			|||||||
	return func() (core.ApiVersion, core.GroupSetupFn) {
 | 
						return func() (core.ApiVersion, core.GroupSetupFn) {
 | 
				
			||||||
		return "v0", func(group *routegroup.Bundle) {
 | 
							return "v0", func(group *routegroup.Bundle) {
 | 
				
			||||||
			csrfMiddleware := csrf.New(func(r *http.Request) string {
 | 
								csrfMiddleware := csrf.New(func(r *http.Request) string {
 | 
				
			||||||
				return session.GetString(r.Context(), "csrf_token")
 | 
									return session.GetData(r.Context()).CsrfToken
 | 
				
			||||||
			}, func(r *http.Request, token string) {
 | 
								}, func(r *http.Request, token string) {
 | 
				
			||||||
				session.Put(r.Context(), "csrf_token", token)
 | 
									currentSession := session.GetData(r.Context())
 | 
				
			||||||
 | 
									currentSession.CsrfToken = token
 | 
				
			||||||
 | 
									session.SetData(r.Context(), currentSession)
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			group.Use(session.LoadAndSave)
 | 
								group.Use(session.LoadAndSave)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -295,6 +295,9 @@ func (e AuthEndpoint) handleOauthCallbackGet() http.HandlerFunc {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (e AuthEndpoint) setAuthenticatedUser(r *http.Request, user *domain.User) {
 | 
					func (e AuthEndpoint) setAuthenticatedUser(r *http.Request, user *domain.User) {
 | 
				
			||||||
 | 
						// start a fresh session
 | 
				
			||||||
 | 
						e.session.DestroyData(r.Context())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	currentSession := e.session.GetData(r.Context())
 | 
						currentSession := e.session.GetData(r.Context())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	currentSession.LoggedIn = true
 | 
						currentSession.LoggedIn = true
 | 
				
			||||||
@@ -358,12 +361,12 @@ func (e AuthEndpoint) handleLoginPost() http.HandlerFunc {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// handleLogoutPost returns a gorm Handler function.
 | 
					// handleLogoutPost returns a gorm Handler function.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// @ID auth_handleLogoutGet
 | 
					// @ID auth_handleLogoutPost
 | 
				
			||||||
// @Tags Authentication
 | 
					// @Tags Authentication
 | 
				
			||||||
// @Summary Get all available external login providers.
 | 
					// @Summary Get all available external login providers.
 | 
				
			||||||
// @Produce json
 | 
					// @Produce json
 | 
				
			||||||
// @Success 200 {object} []model.LoginProviderInfo
 | 
					// @Success 200 {object} model.Error
 | 
				
			||||||
// @Router /auth/logout [get]
 | 
					// @Router /auth/logout [post]
 | 
				
			||||||
func (e AuthEndpoint) handleLogoutPost() http.HandlerFunc {
 | 
					func (e AuthEndpoint) handleLogoutPost() http.HandlerFunc {
 | 
				
			||||||
	return func(w http.ResponseWriter, r *http.Request) {
 | 
						return func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		currentSession := e.session.GetData(r.Context())
 | 
							currentSession := e.session.GetData(r.Context())
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,7 +43,6 @@ type SessionWrapper struct {
 | 
				
			|||||||
func NewSessionWrapper(cfg *config.Config) *SessionWrapper {
 | 
					func NewSessionWrapper(cfg *config.Config) *SessionWrapper {
 | 
				
			||||||
	sessionManager := scs.New()
 | 
						sessionManager := scs.New()
 | 
				
			||||||
	sessionManager.Lifetime = 24 * time.Hour
 | 
						sessionManager.Lifetime = 24 * time.Hour
 | 
				
			||||||
	sessionManager.IdleTimeout = 1 * time.Hour
 | 
					 | 
				
			||||||
	sessionManager.Cookie.Name = cfg.Web.SessionIdentifier
 | 
						sessionManager.Cookie.Name = cfg.Web.SessionIdentifier
 | 
				
			||||||
	sessionManager.Cookie.Secure = strings.HasPrefix(cfg.Web.ExternalUrl, "https")
 | 
						sessionManager.Cookie.Secure = strings.HasPrefix(cfg.Web.ExternalUrl, "https")
 | 
				
			||||||
	sessionManager.Cookie.HttpOnly = true
 | 
						sessionManager.Cookie.HttpOnly = true
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user