Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

feat: Sanitize iframe URL #3809

Merged
merged 4 commits into from
Apr 25, 2022
Merged

feat: Sanitize iframe URL #3809

merged 4 commits into from
Apr 25, 2022

Conversation

yagopv
Copy link
Member

@yagopv yagopv commented Apr 25, 2022

What it solves

Sanitize iframe URL for avoid any JS execution

@yagopv yagopv requested a review from dasanra April 25, 2022 11:14
@github-actions
Copy link

github-actions bot commented Apr 25, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 1 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@github-actions
Copy link

Deployment links

🟠 Rinkeby Mainnet 🟣 Polygon 🟡 BSC Arbitrum 🟢 Gnosis Chain

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

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

The isSameURL() check will fail here as your comparing the sanitized URL with the original appUrl. It's probably best to santiize inside useSafeAppUrl(). What do you think?

@katspaugh
Copy link
Member

I don't think you need HTML entity unescaping. React isn't inserting the iframe URL in HTML, it sets it as a DOM property.
So if someone passes a URL in HTML encoding, it will be inserted as is.

@yagopv
Copy link
Member Author

yagopv commented Apr 25, 2022

I don't think you need HTML entity unescaping. React isn't inserting the iframe URL in HTML, it sets it as a DOM property. So if someone passes a URL in HTML encoding, it will be inserted as is.

Yeah I can remove it. I took the script from a library and is working with more cases than our concrete one

@katspaugh
Copy link
Member

katspaugh commented Apr 25, 2022

It would be nice to show an error straight away.

Screenshot 2022-04-25 at 14 27 29

After N seconds:
Screenshot 2022-04-25 at 14 27 45

Also it showed a disclaimer modal. I think when we see a JavaScript URL, we should just immediately tell the user they are likely being phished.

@yagopv
Copy link
Member Author

yagopv commented Apr 25, 2022

The isSameURL() check will fail here as your comparing the sanitized URL with the original appUrl. It's probably best to santiize inside useSafeAppUrl(). What do you think?

I did it. Moved to the hook. I changed the location of the function itself and added the tests

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

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

Looks really good dude! Thanks for adding the tests as well! What do you think about redirecting to the Apps page if the sanitizer returns an empty string? It still remains in the URL:

sanitize

@katspaugh
Copy link
Member

Redirecting to Apps IMHO would be no bueno, as it will not alert the user and hide the problem.
If they stay on that page and see an error, they will be aware of potential phishing attempts.

@yagopv
Copy link
Member Author

yagopv commented Apr 25, 2022

Redirecting to Apps IMHO would be no bueno, as it will not alert the user and hide the problem.
If they stay on that page and see an error, they will be aware of potential phishing attempts.

I like the error approach. Take a look now. I'm throwing an error if the sanitize call detect a javascript: injection warning the user

@katspaugh
Copy link
Member

It crashes the app immediately now, good 👍

The error is generic tho, something we could improve. But good enough for now.
Screenshot 2022-04-25 at 16 35 49

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

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

Nice work 🚀

Copy link
Member

@usame-algan usame-algan left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for adding tests 💯

@yagopv
Copy link
Member Author

yagopv commented Apr 25, 2022

@JagoFigueroa did you test this?

@JagoFigueroa
Copy link

Excelente implementación camarada, looks good to me as well.

Un saludo ;)

@yagopv yagopv merged commit 1428e45 into main Apr 25, 2022
@yagopv yagopv deleted the feature/sanitize-iframe-url branch April 25, 2022 15:16
@yagopv yagopv restored the feature/sanitize-iframe-url branch April 25, 2022 15:18
@yagopv yagopv deleted the feature/sanitize-iframe-url branch April 25, 2022 15:19
return relativeFirstCharacters.indexOf(url[0]) > -1
}

export function sanitizeUrl(url: string | null): string {
Copy link
Member

Choose a reason for hiding this comment

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

Why does it allow null as a param?

@dasanra dasanra restored the feature/sanitize-iframe-url branch April 25, 2022 15:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants