Invalid structure generated response from Kratos, error is swallowed
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 178
- Forks
- 96
- Avg merge
- 6d 23h
- Merged PRs (30d)
- 3
Description
Preflight checklist
- I could not find a solution in the existing issues, docs, nor discussions.
- I agree to follow this project's Code of Conduct.
- I have read and am following this repository's Contribution Guidelines.
- I have joined the Ory Community Slack.
- I am signed up to the Ory Security Patch Newsletter.
Ory Network Project
No response
Describe the bug
There is a bug in the Kratos Golang client, where the oneOf(UiNodeAttributes) is always multiple because they all have node_type This error is being returned https://github.com/ory/kratos-client-go/blob/e9aeb0ece9b90a58659db5287a7d4b895d493209/model_ui_node_attributes.go#L141
This error is discarded too because it swallowed here https://github.com/ory/kratos-client-go/blob/e9aeb0ece9b90a58659db5287a7d4b895d493209/model_ui_node.go#L202-L204
Reproducing the bug
package main
import (
"encoding/json"
kratos "github.com/ory/kratos-client-go"
"log"
)
var data = []byte(`{
"id": "f616cef9-d05b-45ee-aa15-df3e43aadcc6",
"type": "browser",
"expires_at": "2024-02-13T15:25:28.317672Z",
"issued_at": "2024-02-13T15:15:28.317672Z",
"request_url": "[REDACTED]",
"return_to": "[REDACTED]",
"ui": {
"action": "[REDACTED]/.ory/kratos/public/self-service/login?flow=f616cef9-d05b-45ee-aa15-df3e43aadcc6",
"method": "POST",
"nodes": [
{
"type": "input",
"group": "default",
"attributes": {
"name": "csrf_token",
"type": "hidden",
"value": "0rDQ4YfJvOHPgeedwcI6ySPHM9vXWntmu9aYS9iIDLfvk0xVdyMwidYFWk7TP/9U7nkZ2pW3gi4IaS7x/XV7/g==",
"required": true,
"disabled": false,
"node_type": "input"
},
"messages": [],
"meta": {}
},
{
"type": "input",
"group": "default",
"attributes": {
"name": "identifier",
"type": "text",
"value": "",
"required": true,
"disabled": false,
"node_type": "input"
},
"messages": [],
"meta": {
"label": {
"id": 1070004,
"text": "ID",
"type": "info"
}
}
},
{
"type": "input",
"group": "password",
"attributes": {
"name": "password",
"type": "password",
"required": true,
"autocomplete": "current-password",
"disabled": false,
"node_type": "input"
},
"messages": [],
"meta": {
"label": {
"id": 1070001,
"text": "Password",
"type": "info"
}
}
},
{
"type": "input",
"group": "password",
"attributes": {
"name": "method",
"type": "submit",
"value": "password",
"disabled": false,
"node_type": "input"
},
"messages": [],
"meta": {
"label": {
"id": 1010001,
"text": "Sign in",
"type": "info",
"context": {}
}
}
}
]
},
"created_at": "2024-02-13T15:15:28.322643Z",
"updated_at": "2024-02-13T15:15:28.322643Z",
"refresh": false,
"requested_aal": "aal1"
}`)
func main() {
var parsed *kratos.LoginFlow
if err := json.Unmarshal(data, &parsed); err != nil {
log.Fatalf("unable to parse %s", err)
}
for _, v := range parsed.Ui.Nodes {
log.Printf("%+v\n", v.Attributes)
}
}
Relevant log output
2024/02/13 15:39:38 {UiNodeAnchorAttributes:<nil> UiNodeImageAttributes:<nil> UiNodeInputAttributes:<nil> UiNodeScriptAttributes:<nil> UiNodeTextAttributes:<nil>}
2024/02/13 15:39:38 {UiNodeAnchorAttributes:<nil> UiNodeImageAttributes:<nil> UiNodeInputAttributes:<nil> UiNodeScriptAttributes:<nil> UiNodeTextAttributes:<nil>}
2024/02/13 15:39:38 {UiNodeAnchorAttributes:<nil> UiNodeImageAttributes:<nil> UiNodeInputAttributes:<nil> UiNodeScriptAttributes:<nil> UiNodeTextAttributes:<nil>}
2024/02/13 15:39:38 {UiNodeAnchorAttributes:<nil> UiNodeImageAttributes:<nil> UiNodeInputAttributes:<nil> UiNodeScriptAttributes:<nil> UiNodeTextAttributes:<nil>}
### Relevant configuration
_No response_
### Version
`require github.com/ory/kratos-client-go v1.0.0`
### On which operating system are you observing this issue?
None
### In which environment are you deploying?
None
### Additional Context
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with model_ui_node_attributes.go at the referenced oneOf handling and model_ui_node.go around lines 202-204, then run the provided Go JSON-unmarshal reproduction. Done means the Kratos client correctly populates the input attributes for these nodes and does not discard the relevant parsing error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100