Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sizing limits for custom UI #2199

Merged
merged 5 commits into from
Feb 21, 2024
Merged

Add sizing limits for custom UI #2199

merged 5 commits into from
Feb 21, 2024

Conversation

FrederikBolding
Copy link
Member

Adds sizing limits for custom UI input. Previously these inputs were only validated to have the proper formatting.

This PR adds logic to validate that the UI components provided by the Snap are within reasonable length. Both the entire UI component object is serialized to JSON and validated that it's total size is less than 250 kb. Also the total text used in the UI component is validated to be less than 50 kb.

Copy link

codecov bot commented Feb 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fa692b3) 96.58% compared to head (ebadbd3) 96.59%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2199   +/-   ##
=======================================
  Coverage   96.58%   96.59%           
=======================================
  Files         332      332           
  Lines        7564     7582   +18     
  Branches     1171     1175    +4     
=======================================
+ Hits         7306     7324   +18     
  Misses        258      258           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

import { nanoid } from 'nanoid';

import { constructState } from './utils';

const MAX_UI_CONTENT_SIZE = 256000; // 250 kb
Copy link
Member Author

Choose a reason for hiding this comment

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

This limit can probably be larger if we want it to be.

@FrederikBolding FrederikBolding marked this pull request as ready for review February 21, 2024 11:54
@FrederikBolding FrederikBolding requested a review from a team as a code owner February 21, 2024 11:54
*/
export function getTotalTextLength(component: Component): number {
const { type } = component;
if (type === NodeType.Panel) {
Copy link
Member

Choose a reason for hiding this comment

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

Rows can contain text components too.

Mrtenz
Mrtenz previously approved these changes Feb 21, 2024
@FrederikBolding FrederikBolding merged commit c22daab into main Feb 21, 2024
150 checks passed
@FrederikBolding FrederikBolding deleted the fb/ui-size-limits branch February 21, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants