Skip to content

#5959 Modified consent to have permission with redorder of purposes - #131

Merged
brionmario merged 1 commit into
thunder-id:mainfrom
Infosys:task/5959
Oct 27, 2026
Merged

brionmario merged 1 commit into
thunder-id:mainfrom
Infosys:task/5959

Conversation

@zesu22

@zesu22 zesu22 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Purpose

fixes thunder-id/thunderid#5959

Approach

Related Issues

  • N/A

Related PRs

  • N/A

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.
  • Cross-SDK parity. Exactly one of parity/prs-raised or parity/prs-not-needed added.
    • If parity/prs-raised, the port links are posted as a reply on the parity check's comment.

Security checks

  • Followed secure coding standards.
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🔀 Cross-SDK feature parity, no ports needed

This pull request is labelled parity/prs-not-needed: nothing here has to ship in the other ThunderID SDKs. If that changes, swap the label for parity/prs-raised.


if (purposes.length === 0) return null;

// Order purposes so that permissions come first and attributes come last.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai Can you evaluate if there's any perf hit due to this block being run on every render?
Also check for any possible NPEs?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brionmario The sort adds work on every render, but it is unlikely to matter for a small purpose list. There are runtime null-safety gaps for malformed input. This assessment is based on static inspection, not profiling.

Performance

  • [...purposes] copies the array: O(n) time and allocation.
  • .sort(...) typically adds O(n log n) work. The comparator is inexpensive.
  • This repeats when formValues changes, even when consentData stays unchanged.
  • If consentData is a string, JSON.parse also repeats on every render.

The copy correctly prevents mutation of the caller’s array. I would keep it.

If purpose lists can become large, memoize parsing, validation, and sorting together with useMemo(..., [consentData]). Place that hook before all conditional returns. For array/object inputs, memoization requires consumers to replace the input reference when the data changes.

Null-safety and malformed input

Valid ConsentPurposeData[] input is safe for this comparator. Missing type values also do not throw; they sort with non-permission purposes.

However, JSON.parse does not validate the data shape:

Input Current behavior
'null' or invalid JSON Returns null; the existing catch handles it.
'[null, {}]' The comparator can throw when it reads .type on null.
'[null]' Sorting does not need a comparison, but the default render throws at purpose.type.
'{"purposes": {}}' The spread throws because purposes is not iterable.
A valid purpose with optional: [null] checkOptValue throws when it reads opt.name.

The sort sits outside the try/catch, so that catch does not protect it. Some malformed inputs already fail in the existing rendering code; the comparator adds another failure point.

Recommendation: Validate the decoded value before sorting. Require an array of non-null purpose objects and validate the essential/optional arrays and their elements before rendering. Optional chaining in the comparator alone would only move the failure into the render code.

The existing purpose.optional?.length > 0 guard does protect checkOptValue and handleChange from a missing or null optional array during normal rendering.

You are interacting with an AI system.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zesu22 Can you please check if the supplied suggestions are valid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brionmario I have changed the code according to the coderabbit comment, added memoizing the function as well proper validation on that.

@brionmario brionmario added the parity/prs-not-needed Nothing here reaches another SDK label Oct 26, 2026
@brionmario

Copy link
Copy Markdown
Member

Adding parity/prs-not-needed sinde we don't have Consent related features in the Mobile SDKs

Signed-off-by: Zeeshan Mehboob <zeeshan.mehboob@infosys.com>
@brionmario
brionmario merged commit 056cbb0 into thunder-id:main Oct 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity/prs-not-needed Nothing here reaches another SDK

Projects

None yet

2 participants