microsoft / microsoft/AdaptiveCards

AdaptiveCard.FromJson, AdaptiveCardTemplate Support Newtonsoft 13 with higher than 64 max depth

Open
#7,470 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Renderers Bug Security
Dominant language
C#
Stars
2k
Forks
595
Avg merge
1d 19h
Merged PRs (30d)
1

Description

Target Platforms

Other

SDK Version

2.7.3

Application Name

Custom Application

Problem Description

Can you please support Newtonsoft version 13, when Newtonsoft version 12 is used this bug does not happen but version 12 has a security vulnerability.

https://security.snyk.io/vuln/SNYK-DOTNET-NEWTONSOFTJSON-2774678

the JsonSerializerSettings needs a MaxDepth = int.MaxValue, as in version 13 a small default max depth has been introduced.

This exact error is caused when applying the template in the AdaptiveCardTemplate constructor but will also happen again inside the AdaptiveCard.FromJson call if the maxdepth is not applied to both areas of the code.

AdaptiveCards.Templating.AdaptiveTemplateException
HResult=0x80131500
Message=Setting root data failed with given data context
Source=AdaptiveCards.Templating
StackTrace:
at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor..ctor(Func2 nullSubstitutionOption, String data) at AdaptiveCards.Templating.AdaptiveCardTemplate.Expand(EvaluationContext context, Func2 nullSubstitutionOption)
at AdaptiveCards.Templating.AdaptiveCardTemplate.Expand(Object rootData, Func`2 nullSubstitutionOption)
at BottKitt.Bot.Flow.FlowDialogConverter.<>c__DisplayClass56_0.<b__0>d.MoveNext() in

This exception was originally thrown at this call stack:
[External Code]

Inner Exception 1:
JsonReaderException: The reader's MaxDepth of 64 has been exceeded. Path '$tenjinInterpolatedVariables.conversation.DialogState.dialogStack[0].state.dialogs.dialogStack[0].state.dialogs.dialogStack[0].state.dialogs.dialogStack[0].state._adaptive.actions[0].dialogStack[0].state.dialogs.dialogStack[0].state._adaptive.actions[0].dialogStack[0].state.dialogs.dialogStack[0].state._adaptive.actions[0].dialogStack[0].state.dialogs.dialogStack[0].state._adaptive.actions[0].dialogStack[0].state.dialogs.dialogStack[0].state._adaptive.actions[0].dialogStack[0].state', line 1, position 6345.

Screenshots

No response

Card JSON
{
  "type": "AdaptiveCard",
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.3",
  "body": [
    {
      "type": "TextBlock",
      "text": "No comments found for ${incident.Number}",
      "id": "nocomments_text",
      "$when": "${totalComments == 0}"
    },
    {
      "type": "Container",
      "$when": "${totalComments > 0}",
      "items": [
        {
          "type": "ColumnSet",
          "columns": [
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "${incident.Number} comments",
                  "wrap": true,
                  "id": "card_title"
                }
              ]
            },
            {
              "type": "Column",
              "width": "auto",
              "items": [
                {
                  "type": "TextBlock",
                  "text": "Page ${currentPage} of ${totalPages}",
                  "wrap": true,
                  "id": "card_pageinfo"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "Container",
      "$data": "${comments}",
      "items": [
        {
          "type": "ColumnSet",
          "spacing": "Medium",
          "columns": [
            {
              "type": "Column",
              "width": "auto",
              "items": [
                {
                  "type": "Image",
                  "url": "${User.PhotoUrl}",
                  "style": "Person",
                  "size": "Small",
                  "$when": "${User.PhotoUrl != ''}"
                },
                {
                  "type": "Image",
                  "url": "images/servicenow_icon.png",
                  "style": "Person",
                  "size": "Small",
                  "$when": "${User.PhotoUrl == ''}"
                }
              ]
            },
            {
              "type": "Column",
              "width": "stretch",
              "items": [
                {
                  "type": "ColumnSet",
                  "columns": [
                    {
                      "type": "Column",
                      "width": "stretch",
                      "items": [
                        {
                          "type": "TextBlock",
                          "text": "${User.DisplayName}",
                          "wrap": true,
                          "weight": "Bolder"
                        }
                      ]
                    },
                    {
                      "type": "Column",
                      "width": "auto",
                      "verticalContentAlignment": "Bottom",
                      "items": [
                        {
                          "type": "TextBlock",
                          "text": "{{DATE(${CreatedDate}, COMPACT)}}",
                          "wrap": true,
                          "size": "Small"
                        }
                      ]
                    }
                  ]
                },
                {
                  "type": "TextBlock",
                  "text": "${Comment}",
                  "wrap": true,
                  "spacing": "Small"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}
Sample Code Language

c#

Sample Code

AdaptiveCard.FromJson(new AdaptiveCardTemplate(templateJson).Expand(rootData)).Card;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the AdaptiveCardTemplate constructor and Expand path, then inspect AdaptiveCard.FromJson in the C# SDK to see where Newtonsoft.Json settings are created. Verify both parsing paths handle Newtonsoft 13's depth limit, and use the supplied deeply nested card and sample call to confirm expansion and parsing complete without the MaxDepth exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.