[PR #1177] [CLOSED] fix: prevent runtime.TypeAssertionError in openid provider parsing #1301

Closed
opened 2025-11-01 21:15:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-vikunja/vikunja/pull/1177
Author: @Copilot
Created: 7/25/2025
Status: Closed

Base: mainHead: copilot/fix-1175


📝 Commits (2)

  • 31a733a Initial plan
  • beb8968 fix: prevent runtime.TypeAssertionError in openid provider parsing

📊 Changes

1 file changed (+10 additions, -4 deletions)

View changed files

📝 pkg/modules/auth/openid/providers.go (+10 -4)

📄 Description

Problem

The application was crashing with a runtime.TypeAssertionError when parsing OpenID Connect provider configurations:

runtime.TypeAssertionError: interface conversion: interface {} is []interface {}, not map[interface {}]interface {}

This occurred in pkg/modules/auth/openid/providers.go at line 58, where the code was making an unsafe type assertion assuming that if a provider configuration wasn't a map[string]interface{}, it must be a map[interface{}]interface{}. However, misconfigured or malformed provider configs could result in other types like []interface{}, causing the application to panic.

Solution

Added proper type checking before the type assertion:

// Before (unsafe)
pis := p.(map[interface{}]interface{})

// After (safe)
if pis, isMap := p.(map[interface{}]interface{}); isMap {
    // Convert the map...
} else {
    // Log error and skip invalid provider
    log.Errorf("Skipping openid provider %s: expected map but got %T", key, p)
    continue
}

Impact

  • Prevents crashes: The /info endpoint and other OpenID functionality now handle invalid provider configurations gracefully
  • Better error handling: Invalid configurations are logged with descriptive error messages instead of causing panics
  • Backward compatibility: All existing valid configurations continue to work unchanged
  • Minimal change: Only 10 lines changed, maintaining the existing logic flow

The fix ensures that even with malformed OpenID provider configurations, the application continues to run and provides useful error information for debugging.

Fixes #1175.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-vikunja/vikunja/pull/1177 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 7/25/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `copilot/fix-1175` --- ### 📝 Commits (2) - [`31a733a`](https://github.com/go-vikunja/vikunja/commit/31a733aacf6683dce468d0bb09e03a92f4e1ddfd) Initial plan - [`beb8968`](https://github.com/go-vikunja/vikunja/commit/beb89684e3f3a12b988dbaaec6582d42a62e005d) fix: prevent runtime.TypeAssertionError in openid provider parsing ### 📊 Changes **1 file changed** (+10 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `pkg/modules/auth/openid/providers.go` (+10 -4) </details> ### 📄 Description ## Problem The application was crashing with a `runtime.TypeAssertionError` when parsing OpenID Connect provider configurations: ``` runtime.TypeAssertionError: interface conversion: interface {} is []interface {}, not map[interface {}]interface {} ``` This occurred in `pkg/modules/auth/openid/providers.go` at line 58, where the code was making an unsafe type assertion assuming that if a provider configuration wasn't a `map[string]interface{}`, it must be a `map[interface{}]interface{}`. However, misconfigured or malformed provider configs could result in other types like `[]interface{}`, causing the application to panic. ## Solution Added proper type checking before the type assertion: ```go // Before (unsafe) pis := p.(map[interface{}]interface{}) // After (safe) if pis, isMap := p.(map[interface{}]interface{}); isMap { // Convert the map... } else { // Log error and skip invalid provider log.Errorf("Skipping openid provider %s: expected map but got %T", key, p) continue } ``` ## Impact - **Prevents crashes**: The `/info` endpoint and other OpenID functionality now handle invalid provider configurations gracefully - **Better error handling**: Invalid configurations are logged with descriptive error messages instead of causing panics - **Backward compatibility**: All existing valid configurations continue to work unchanged - **Minimal change**: Only 10 lines changed, maintaining the existing logic flow The fix ensures that even with malformed OpenID provider configurations, the application continues to run and provides useful error information for debugging. Fixes #1175. <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-01 21:15:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#1301