Skip to content

URI encode template replacement to avoid XSS #38

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

Merged
merged 3 commits into from
Oct 2, 2023
Merged

URI encode template replacement to avoid XSS #38

merged 3 commits into from
Oct 2, 2023

Conversation

SiCoe
Copy link

@SiCoe SiCoe commented Sep 22, 2023

A pentest has highlighted where we need to encode user input to avoid potential XXS attacks.

I think I've narrowed it down to this repo and this change should mitigate the risk.

I looks like this has already been done for the openid.index.js, so I followed the same implementation in pkce.index.js

@SiCoe SiCoe requested review from anevis and iress-ac September 22, 2023 12:56
@SiCoe SiCoe changed the base branch from master to v4 September 25, 2023 11:47
@SiCoe SiCoe added this to the v4 milestone Sep 25, 2023
page = page.replace(/%error_description%/g, error_description);
page = page.replace(/%error_uri%/g, error_uri);
page = page.replace(/%error%/g, encodeURI(error).replace(/%20/g,' '));
page = page.replace(/%error_description%/g, encodeURI(error_description).replace(/%20/g,' '));

Choose a reason for hiding this comment

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

This may make the supplied string "safe" but I don't think URI encoding is what e are going to want. encodeURI is designed to encode urls not strings shown as HTML. I think we will need some form of HTML Encoding instead.

For example when encoding the string <script>alert('boo & hiss');</script> the encodeURI results in %3Cscript%3Ealert('boo%20&%20hiss');%3C/script%3E.
Where as I think we would want it to be displayed as &lt;script&gt;alert('boo &amp; hiss');&lt;/script&gt;

I don't think there is a native function for HTML encoding in JavaScript, but some searching will confirm or deny a soln there.

Copy link
Author

Choose a reason for hiding this comment

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

I think you're right, HTML encoding will be better than URI encoding for this text.
I'll look at moving it over, and probably also update it in the openid.index.js file as well to align them.

Copy link
Author

Choose a reason for hiding this comment

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

I've installed and used the entities npm package to do HTML encoding instead of URI for both files.

Choose a reason for hiding this comment

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

@SiCoe quick follow up question... have you checked adding the additional package does not break the size limit for lambda@edge functions as mentioned in the readme?

Choose a reason for hiding this comment

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

the entites package looks good from a health pov but I notice it has a BSD-2-Clause licence. Is that licence compatible with this repo?

Choose a reason for hiding this comment

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

Looks like the size of the package listed in the action results is under the required 1MB
Screenshot 2023-09-26 at 11 45 24

Copy link
Author

Choose a reason for hiding this comment

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

the entites package looks good from a health pov but I notice it has a BSD-2-Clause licence. Is that licence compatible with this repo?

@kristens-work do you know, or know anyone who's able to advise on use of a BSD 2 Clause licenced dependencies within our open-source repositories?

Choose a reason for hiding this comment

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

I tend to seek advice from Rebecca Kelly on opensource licencing

Copy link
Author

Choose a reason for hiding this comment

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

the entites package looks good from a health pov but I notice it has a BSD-2-Clause licence. Is that licence compatible with this repo?

I've replaced the dependency on the BSD-2-Clause entities package with a dependency on the MIT html-entities package.

Choose a reason for hiding this comment

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

I'm happy that resolves the licensing question to no detriment to the code base.

@SiCoe SiCoe changed the title URI encode template replacement to ovoid XSS URI encode template replacement to avoid XSS Sep 25, 2023
@SiCoe SiCoe requested a review from steve-forth September 25, 2023 17:19
This is due to licensing consern. 'html-entities' is distributed with the MIT license .
@SiCoe SiCoe requested a review from kristens-work October 2, 2023 09:32
@SiCoe SiCoe merged commit 1d9f87a into v4 Oct 2, 2023
@SiCoe SiCoe deleted the DP-803 branch October 2, 2023 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants