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

[HOLD for payment 2023-08-10] [$1000] Handle mentions renderer not receiving props #23811

Closed
puneetlath opened this issue Jul 28, 2023 · 26 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@puneetlath
Copy link
Contributor

puneetlath commented Jul 28, 2023

Problem

If for some reason the back-end doesn't return props that the mentions renderer expects, this causes the app to crash.

Solution

In the mentions renderer, handle the case where the expected props aren't provided.

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0125cc67eabd576779
  • Upwork Job ID: 1684978455578161152
  • 2023-07-28
  • Automatic offers:
    • aimane-chnaif | Reviewer | 25816064
    • tienifr | Contributor | 25816067
@puneetlath puneetlath added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 28, 2023
@puneetlath puneetlath self-assigned this Jul 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

Triggered auto assignment to @mallenexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot

This comment was marked as off-topic.

@puneetlath puneetlath added the External Added to denote the issue can be worked on by a contributor label Jul 28, 2023
@melvin-bot melvin-bot bot changed the title Handle mentions renderer not receiving props [$1000] Handle mentions renderer not receiving props Jul 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0125cc67eabd576779

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

Triggered auto assignment to @muttmuure (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (External)

@puneetlath
Copy link
Contributor Author

I'm going to assign this to @tienifr as we have already discussed this over email. @tienifr can you please post your proposal here?

@tienifr
Copy link
Contributor

tienifr commented Jul 28, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

The MentionUserRenderer makes the app crash when rendering nested mention. This could be exploited to make any user’s app crash

What is the root cause of that problem?

In

const loginWithoutLeadingAt = props.tnode.data.slice(1);

we are removing the first character of the mention text with props.tnode.data.slice(1). This would work when the markdown component is a single component - which will be understood as a TText node. However, when an attacker purposely send a nested mention, the props.tnode value is a TPhrasing object, and this does not have the data value, which will cause the app to crash since props.tnode.data is undefined.

What changes do you think we should make in order to solve the problem?

We need to check if props.tnode.data is actually valid before applying the slice function

- const loginWithoutLeadingAt = props.tnode.data.slice(1);
+ const loginWithoutLeadingAt = props.tnode.data ? props.tnode.data.slice(1) : null;

or something like

- const loginWithoutLeadingAt = props.tnode.data.slice(1);
- const isOurMention = loginWithoutLeadingAt === props.currentUserPersonalDetails.login;
+ const isOurMention = props.tnode.data && props.tnode.data.slice(1) === props.currentUserPersonalDetails.login;

@tienifr
Copy link
Contributor

tienifr commented Jul 28, 2023

@puneetlath I've posted my proposal above. Can you help take a look at it?

@aimane-chnaif
Copy link
Contributor

can anyone please share repro step to crash?

@tienifr
Copy link
Contributor

tienifr commented Jul 28, 2023

STEPS TO REPRODUCE

  1. In
    buildOptimisticAddCommentReportAction

Change from

const commentText = getParsedComment(text);

to

const commentText = text;

By doing this, we can customize and send any markdown texts to any users.

  1. Open any report to any user, send this text: <mention-user><mention-here>here</mention-here></mention-user>
  2. Notice the app crashes in both the sending and receiving accounts.

@tienifr
Copy link
Contributor

tienifr commented Jul 28, 2023

@aimane-chnaif Here you are #23811 (comment)

@saalimzafar
Copy link

function MentionUserRenderer(props) {
// Check if the required props exist
if (!props.tnode || !props.currentUserPersonalDetails) {
// Return a fallback UI or null when required props are missing
return null;
}

// Rest of the component's logic

@aimane-chnaif
Copy link
Contributor

does nested mention happen in real world?

@aimane-chnaif
Copy link
Contributor

@tienifr null causes another crash. Empty string is fine.

const loginWithoutLeadingAt = props.tnode.data ? props.tnode.data.slice(1) : '';

I am still curious if we can send that weird message without any dev code change.
Anyway, good one to fix as bad guy can send this to any public room which makes everyone crashes. Even not able to delete because of crash.

🎀 👀 🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

Triggered auto assignment to @danieldoglas, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@puneetlath
Copy link
Contributor Author

@danieldoglas I'll take this since it deals with mentions and I'm already assigned here: https://github.com/Expensify/Expensify/issues/302711

@puneetlath puneetlath assigned tienifr and unassigned danieldoglas Jul 28, 2023
@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jul 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

📣 @aimane-chnaif 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

📣 @tienifr 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@puneetlath puneetlath added Weekly KSv2 and removed Daily KSv2 labels Jul 28, 2023
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Weekly KSv2 labels Jul 29, 2023
@tienifr
Copy link
Contributor

tienifr commented Jul 29, 2023

The PR #23845 is ready for review

@melvin-bot
Copy link

melvin-bot bot commented Aug 1, 2023

🎯 ⚡️ Woah @aimane-chnaif / @tienifr, great job pushing this forwards! ⚡️

The pull request got merged within 3 working days of assignment, so this job is eligible for a 50% #urgency bonus 🎉

  • when @tienifr got assigned: 2023-07-28 19:48:22 Z
  • when the PR got merged: 2023-08-01 15:58:35 UTC

On to the next one 🚀

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Aug 3, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Handle mentions renderer not receiving props [HOLD for payment 2023-08-10] [$1000] Handle mentions renderer not receiving props Aug 3, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Aug 3, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 3, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot
Copy link

melvin-bot bot commented Aug 3, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.49-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-08-10. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

For reference, here are some details about the assignees on this issue:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Aug 3, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@aimane-chnaif] The PR that introduced the bug has been identified. Link to the PR:
  • [@aimane-chnaif] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@aimane-chnaif] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@aimane-chnaif] Determine if we should create a regression test for this bug.
  • [@aimane-chnaif] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@puneetlath] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Aug 9, 2023
@puneetlath
Copy link
Contributor Author

@aimane-chnaif friendly bump on the checklist.

@tienifr has been paid.

@aimane-chnaif
Copy link
Contributor

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

As this is extreme edge case, regression test is not needed

@puneetlath
Copy link
Contributor Author

All paid. Thanks y'all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

7 participants