GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [vf] [New Rule] Handle XSS violations that can occur within Html Style tags by rmohan20 · Pull Request #3005 · pmd/pmd

Conversation

@rmohan20

@rmohan20 rmohan20 commented Jan 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Describe the PR

This PR introduces a new rule, VfHtmlStyleTagXss, to check encoding in <style/> tags that are present in visualforce code.

This rule is based on Salesforce Security's recommendation to prevent XSS in Visualforce as mentioned here.

Currently, in PMD, while the <script/> tag rules are already handled thoroughly, <style/> tag rules have been missing. The newly added rule expects URLENCODING or JSINHTMLENCODING for url-based style values and any kind of encoding for non-url style values.

cc @jbartolotta-sfdc

The new rule throws violations for:

  1. No encoding at all for non-url based value in style tag:
<apex:page>
<style>
a { {!XSSHere} }
</style>
</apex:page>
  1. No encoding at all for url-based value in style tag:
<apex:page>
<style>
 div {
  background: url('{!XSSHere}');
}
</style>
</apex:page>
  1. HTML encoding for url-based value in style tag:
<apex:page>
<style>
 div {
  background: url('{!HTMLENCODE(XSSHere)}');
}
</style>
</apex:page>
  1. JS encoding for url-based value in style tag:
<apex:page>
<style>
 div {
  background: url('{!JSENCODE(XSSHere)}');
}
</style>
</apex:page>

The new rule allows:

  1. Any encoding for non-url based value in style tag:
<apex:page>
<style>
a { {!HTMLENCODING(XSSHere)} }
</style>
</apex:page>

(HTMLENCODING can be replaced with JSENCODING, JSINHTMLENCODING and URLENCODING - no violation will be thrown)

  1. JS in HTML encoding for url-based value in style tag:
<apex:page>
<style>
 div {
  background: url('{!JSINHTMLENCODE(XSSHere)}');
}
</style>
</apex:page>
  1. URL encoding for url-based value in style tag:
<apex:page>
<style>
 div {
  background: url('{!URLENCODE(XSSHere)}');
}
</style>
</apex:page>

Related issues

No relevant open issue exists at the moment.

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by travis)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
rmohan20 added 5 commits December 16, 2020 09:40
@rmohan20 GitHub Enterprise
Merge pull request pmd#9 from isv-swat/getLatestFromGithub/12/16/2020
ec1718c
Get latest from GitHub/12/16/2020
@rmohan20
Redoing HTML Style tag changes on updated Typecheck logic
35ee2a5
@rmohan20
Changes to fix apex namespace bug
94a3eb6
@rmohan20
Merging Style tag and HTML XSS checks with typecheck changes for real
7fc3dee
@rmohan20
parent 7fc3dee
407aa69
author rmohan <[email protected]> 1608240897 -0800
committer rmohan <[email protected]> 1610153787 -0800
gpgsig -----BEGIN PGP SIGNATURE-----

 iQIzBAABCAAdFiEEPykD30Ug+JG+ZQ7x5XWwXqT2VuwFAl/4/zsACgkQ5XWwXqT2
 VuwJoBAAsdl/TU3nculnOPwrCHtaxgtM/4zB+wLdw7f+KtIaGMv5A8v8gMbqh0V+
 OTPV0Q/CTEk4PxA2qD5aCPLOaO9+LHOKjPdkWalttVjINtTVPR2pKo0PKR+f2q77
 79eFkhiB1uNx741ThGIZoWPv8eMKHYP+1BEwndFdByxSA70+gdYkbmZqKLLOOrTE
 2uxuGwnNM02ZYskupvgPW2pZvWFviR2sZt/GbFPkqAwgjf40MxM5+3cujOOV850E
 hLHCcch5G5sh8sHTb9nCyNmc6i1kSw9+OOpOHmJGV4u3DRBBtTE9FdwyEUJ2VliZ
 77VrfRPxwzkAE3jTH7EGCY7kpf84jQMqrGn/gav1LfH4DscPZmF617r9iYZ5fOr6
 Z2Fun4vaCXk0h1CojCOpnh4WAthhiVtvBJmdiyO489/hmbtwWuz7KBkCsEVBS+8E
 ViEaQylIOWjcFXkAq5PQ8fCxIqqMgbI7p5kQL6zatpykteMT5zoJj41t8oyjr5Rz
 RUGXNPxpW3zKq3jw4VsjZ8qNYuoSerTzx0qGuUQIALO97HZ8ZBsxmcDTFJrzAkj7
 yfslzLRIoPlL4ZKdpOgCGzVLBX1D/YCBn9KXQiYEYRh57umIt0wpM/Y/Xkl+/Jr4
 97DYj7GQr1gYavSqe7z5n3aUixyibpWy/wx2K3VN6PmtZ3FEB5I=
 =dqIs
 -----END PGP SIGNATURE-----

Creating new VfHtmlStyleTagXss rule to handle XSS in style tags.
Also, refactoring common code out of VfUnescapeElRule to avoid duplication.
rmohan20
rmohan20 commented Jan 11, 2021
View reviewed changes
Comment thread ...sualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfHtmlStyleTagXssRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

rmohan20
rmohan20 commented Jan 11, 2021
View reviewed changes
Comment thread pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

rmohan20
rmohan20 commented Jan 11, 2021
View reviewed changes
Comment thread ...isualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/lib/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

rmohan20
rmohan20 commented Jan 11, 2021
View reviewed changes
Comment thread .../java/net/sourceforge/pmd/lang/vf/rule/security/VfHtmlXssStyleTagUrlPatternMatchingTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rmohan20
rmohan20 marked this pull request as ready for review January 11, 2021 19:52
@rmohan20

rmohan20 commented Jan 12, 2021

Copy link
Copy Markdown
Contributor Author

@adangel @rsoesemann can you please have a look at this PR when you get a chance and let me know what you think? This has a few new XSS checks for Visualforce.

rsoesemann reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rsoesemann
rsoesemann approved these changes Jan 12, 2021
View reviewed changes

@rsoesemann rsoesemann left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks great. I couldn't find anything I didn't like. @adangel you?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rmohan20 reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@rmohan20

rmohan20 commented Jan 14, 2021

Copy link
Copy Markdown
Contributor Author

@rsoesemann Thanks for the approval.
@adangel Would love to hear your thoughts on this PR as well.
FYI, starting next week, I'll be on a break till mid-March and may not be able to address any new feedback until then.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann

rsoesemann commented Jan 14, 2021

Copy link
Copy Markdown
Member

Maybe also @oowekyala can have second look.

rmohan20 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Jan 15, 2021
@adangel adangel added this to the 6.31.0 milestone Jan 15, 2021
@oowekyala
oowekyala self-requested a review January 15, 2021 17:15
oowekyala
oowekyala reviewed Jan 15, 2021
View reviewed changes

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@rmohan20 Thanks for working on this, especially, for the thorough explanations. I can fix those comments myself if you're away, let me know

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rmohan20 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread ...sualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfHtmlStyleTagXssRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...sualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfHtmlStyleTagXssRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...isualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/lib/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...isualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/lib/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...isualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/lib/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...isualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/lib/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...isualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/lib/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...isualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/lib/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rmohan20
Applying changes from review feedback
6a17998
rmohan20
rmohan20 commented Jan 15, 2021
View reviewed changes
Comment thread ...force/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/internal/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

rmohan20
rmohan20 commented Jan 15, 2021
View reviewed changes
Comment thread ...force/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/internal/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

rmohan20
rmohan20 commented Jan 15, 2021
View reviewed changes
Comment thread ...force/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/internal/ElEscapeDetector.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

rmohan20
rmohan20 commented Jan 15, 2021
View reviewed changes
Comment thread ...sualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfHtmlStyleTagXssRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

rmohan20
rmohan20 commented Jan 15, 2021
View reviewed changes
Comment thread pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rmohan20

rmohan20 commented Jan 15, 2021

Copy link
Copy Markdown
Contributor Author

@oowekyala Thanks for the thorough review. I've made the changes based on your feedback. Will check back during the weekend to see if you have more suggestions.

rsoesemann reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost

ghost commented Jan 15, 2021

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala
oowekyala approved these changes Jan 16, 2021
View reviewed changes
Comment thread .../java/net/sourceforge/pmd/lang/vf/rule/security/VfHtmlXssStyleTagUrlPatternMatchingTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...sualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfHtmlStyleTagXssRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

jbartolotta-sfdc and others added 2 commits January 19, 2021 10:11
@jbartolotta-sfdc @oowekyala
Update pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/rule…
98acf1d
…/security/VfHtmlXssStyleTagUrlPatternMatchingTest.java

Co-authored-by: Clément Fournier <[email protected]>
@jbartolotta-sfdc
Convert Pattern to a static final member
15dd878
@adangel adangel self-assigned this Jan 19, 2021
adangel
adangel reviewed Jan 21, 2021
View reviewed changes
Comment thread pmd-visualforce/src/main/resources/category/vf/security.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

adangel
adangel reviewed Jan 21, 2021
View reviewed changes
Comment thread pmd-visualforce/src/main/resources/category/vf/security.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel changed the title [vf] [New Rule] Handle Xss violations that can occur within Html Style tags [vf] [New Rule] Handle XSS violations that can occur within Html Style tags Jan 21, 2021
adangel added a commit that referenced this pull request Jan 21, 2021
@adangel
Fixups for #3005
dc4cdf6
- ElEscapeDetector is utility class now
- Improved description and example of new rule
adangel added a commit that referenced this pull request Jan 21, 2021
@adangel
[doc] Update release notes, refs #3005
2e3d94a
adangel added a commit that referenced this pull request Jan 21, 2021
@adangel
Merge pull request #3005 from rmohan20:removeOnEventEncoding
221c9e7
[vf] [New Rule] Handle XSS violations that can occur within Html Style
tags #3005
@adangel
adangel merged commit 15dd878 into pmd:master Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel left review comments
@rsoesemann rsoesemann rsoesemann approved these changes
@oowekyala oowekyala oowekyala approved these changes
+1 more reviewer
@jbartolotta-sfdc jbartolotta-sfdc jbartolotta-sfdc left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Milestone

6.31.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@rmohan20 @rsoesemann @adangel @jbartolotta-sfdc @oowekyala
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.