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 Salesforce VisualForce language support by sgorbaty · Pull Request #279 · pmd/pmd

Conversation

@sgorbaty

@sgorbaty sgorbaty commented Feb 27, 2017 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Hi @jsotuyod,

This is a brand new VF language support with a Stored XSS security rule.
It looks for Stored XSS in all (but style/script) incorrectly escaped merge fields.

FYI, the style check fails because I have no rights to upload a snapshot to Nexus.
The parser is covered by tests. The major difference compared to say JSP parser is that it also parses the island grammar of EL expression into AST nodes.

I've tested this thoroughly on my end but open to suggestions/feedback.

Cheers,
Sergey

Sorry, something went wrong.

Uh oh!

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

rsoesemann and touzoku reacted with hooray emoji
All reactions
  • 🎉 2 reactions
sergeygorbaty added 30 commits February 14, 2017 14:31
@sergeygorbaty
Initial commit
3dd69e5
@sergeygorbaty
Fixed CompilationUnit not getting called
9bf6c4d
@sergeygorbaty
Fixed script tag and removed unneeded content AST node
d7e89d2
@sergeygorbaty
First rule
b55b546
@sergeygorbaty
Cleanup
5370ffc
@sergeygorbaty
Support for mixed merge fields
3a2b8c7
@sergeygorbaty
XSS in apex:outputText
5c91394
@sergeygorbaty
Fixed up parser unit tests
47b29df
@sergeygorbaty
Renaming rules to security, fixing leading whitespaces
e8b8b5e
@sergeygorbaty
Adding VF project
6974d53
@sergeygorbaty
Code style cleanup
e619c28
@sergeygorbaty
One more unit test
b520331
@sergeygorbaty
Cleanup
f194fcd
@sergeygorbaty
Adding support for html style tag
53446c8
@sergeygorbaty
Fixed BOM and random spacing
86ba85f
@sergeygorbaty
Get rid of last reference to #$
475dd47
@sergeygorbaty
Grammar with support for VFEL methods
90af669
@sergeygorbaty
Small fixes
8af50fb
@sergeygorbaty
Added support for DotExpression and Arguments list
83dc8d6
@sergeygorbaty
Improved the rule to catch escaped values
b5235ba
@sergeygorbaty
Adding support for Content
1863bfb
@sergeygorbaty
Small renaming
276954d
@sergeygorbaty
Fixed floats support
e40aa19
@sergeygorbaty
Cleanup
442c7e2
@sergeygorbaty
Revert
7ba708f
@sergeygorbaty
Improved dot notation and empty EL
c14ef0e
@sergeygorbaty
Support for EL with no quotes
f5a5920
@sergeygorbaty
Support for optional args in EL
21355be
@sergeygorbaty
Style fixes
be7329e
@sergeygorbaty
Context aware escaping
ec456fe
@jsotuyod jsotuyod added the a:new-language Proposal to add a new PMD or CPD language to the main distribution label Feb 27, 2017
@sgorbaty

sgorbaty commented Feb 27, 2017

Copy link
Copy Markdown
Contributor Author

@jsotuyod Done!

All reactions

Sorry, something went wrong.

Uh oh!

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

@sergeygorbaty
Adding VF to the list of supported languages
5c30890
@jsotuyod

jsotuyod commented Feb 28, 2017

Copy link
Copy Markdown
Member

@sgorbaty language order is alphabetical, should be "apex, ecmascript, java, jsp, plsql, pom, vf, vm, wsdl, xml, xsl"

All reactions

Sorry, something went wrong.

Uh oh!

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

sergeygorbaty added 9 commits February 28, 2017 09:39
@sergeygorbaty
Reordering
452bb8e
@sergeygorbaty
Typo fix and tests
a7cf531
@sergeygorbaty
Additional negative test
a4f77df
@sergeygorbaty
Whitelisting of http
6bafe94
@sergeygorbaty
any case http
b0a1cfb
@sergeygorbaty
Whitelisting Labels
e2a6956
@sergeygorbaty
Literal starting with http
3bbd5ca
@sergeygorbaty
Whitelisting ObjectType
02e5440
@sergeygorbaty
Small refactoring
5ebf17e
jsotuyod
jsotuyod reviewed Feb 28, 2017
View reviewed changes
Comment thread pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java Outdated

final ASTText textValue = attr.getFirstDescendantOfType(ASTText.class);
if (textValue != null) {
if (Pattern.compile("\\{(\\w|,|\\.|'|:|\\s)*\\}").matcher(textValue.getImage()).matches()) {

@jsotuyod jsotuyod Feb 28, 2017

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.

consider moving the compiled pattern into a static final field. Regex compilation is a slow process to be done on the fly, specially for constant patterns.

Sorry, something went wrong.

Uh oh!

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

All reactions

@sgorbaty sgorbaty Feb 28, 2017

Copy link
Copy Markdown
Contributor Author

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.

Done

Sorry, something went wrong.

Uh oh!

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

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

}

private boolean doesElContainAnyUnescapedIdentifiers(final ASTElExpression elExpression, List<ESCAPING> escapes) {

@jsotuyod jsotuyod Feb 28, 2017

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.

consider using EnumSet<ESCAPING> rather than a List

Sorry, something went wrong.

Uh oh!

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

All reactions

@sgorbaty sgorbaty Feb 28, 2017

Copy link
Copy Markdown
Contributor Author

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.

Done.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java Outdated
return toReturn;
}

enum ESCAPING {

@jsotuyod jsotuyod Feb 28, 2017

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.

being this an enum (equivalent to a class) rather than a constant, consider renaming it to Escaping to comply better with naming conventions (@adangel we should check our checkstye config, since it missed this one)

Sorry, something went wrong.

Uh oh!

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

All reactions

@adangel adangel Mar 3, 2017

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.

@jsotuyod I had a look at the checkstyle rules. It indeed doesn't detect this case - only uppercase enum name. We use the default TypeName check, and the regex just ensures, that the type name begins with an uppercase letter. But after that, any combination of upper/lower case letters are possible - including all uppercase...
There is however AbbreviationAsWordInName. This check could detect such cases. However, it will probably require net.sourceforge.pmd.PMD to become net.sourceforge.pmd.Pmd.... which looks more correct, but would be a very drastic change....

Sorry, something went wrong.

Uh oh!

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

All reactions

@jsotuyod jsotuyod Mar 3, 2017

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.

@adangel that new check allows for a allowedAbbreviationLength param setting maximum consecutive letters in uppercase, which conveniently defaults to 3, so PMD and CPD would be ok (and technically, PMD is an acronym). We could play with it and see how many violations are found in our codebase / which ones we strongly disagree with, and move on from there.

Sorry, something went wrong.

Uh oh!

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

All reactions
jsotuyod
jsotuyod reviewed Feb 28, 2017
View reviewed changes
Comment thread pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java Outdated
case "$page":
isEscaped = true;
continue;
default:

@jsotuyod jsotuyod Feb 28, 2017

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.

you are definitely missing a break here

Sorry, something went wrong.

Uh oh!

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

All reactions

@sgorbaty sgorbaty Feb 28, 2017

Copy link
Copy Markdown
Contributor Author

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.

yup. Fixed.

Sorry, something went wrong.

Uh oh!

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

All reactions
sergeygorbaty added 5 commits February 28, 2017 13:56
@sergeygorbaty
Adding a unit test and bug fix
329e51c
@sergeygorbaty
Using EnumSet
a700612
@sergeygorbaty
Moving Pattern to final static
64bd577
@sergeygorbaty
Renamed Escaping
ea0fcb6
@sergeygorbaty
Improving detection of safe resources
2af071a
@jsotuyod
jsotuyod merged commit 2af071a into pmd:master Mar 1, 2017
@jsotuyod

jsotuyod commented Mar 1, 2017

Copy link
Copy Markdown
Member

This has been merged and will be included in PMD 5.6.0 and later.

All reactions

Sorry, something went wrong.

Uh oh!

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

@rsoesemann

rsoesemann commented Mar 2, 2017

Copy link
Copy Markdown
Member

@sergeygorbaty I will add a few XPath rules as soon the Up2Go fork contains the merged in language module.

@jsotuyod: can you trigger the update of my fork?

All reactions

Sorry, something went wrong.

Uh oh!

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

@jsotuyod

jsotuyod commented Mar 2, 2017

Copy link
Copy Markdown
Member

@up2go-rsoesemann I can't update any fork for which I have no write repositories. Instructions to do that yourself can be found here

All reactions

Sorry, something went wrong.

Uh oh!

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

@rsoesemann

rsoesemann commented Mar 2, 2017

Copy link
Copy Markdown
Member

Ahh, ok. @adangel has access and did this in the past using a script on a regular basis.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jsotuyod

jsotuyod commented Mar 2, 2017

Copy link
Copy Markdown
Member

@up2go-rsoesemann if it helps, I sync my fork with this script:

#!/bin/bash

git fetch upstream

CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

for branch in "pmd/5.5.x" "pmd/5.4.x" "master"; do
  echo "Synching $branch"
  git checkout $branch
  git pull upstream $branch
  git push
done

git checkout $CURRENT_BRANCH

It will sync 3 branches (master, pmd/5.5.x and pmd 5.4.x) and move back to which ever branch you were in before starting the sync.

The remotes are assumed to be origin for my fork and upstream for this repo, but that's up to how your local copy of the repository is set up.

I could add code to abort on a dirty working copy, but so far I haven't.

rsoesemann 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 commented Mar 3, 2017

Copy link
Copy Markdown
Member

@up2go-rsoesemann I can't update Up2Go/pmd, since you have pushed changes there, that aren't on pmd/pmd yet. Once #281 is merged, these changes will be gone. In future, I'd suggest to create feature branches for pull requests, so that it's easier to keep the master branch updated with upstream while working on a feature...

All reactions

Sorry, something went wrong.

Uh oh!

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

@jsotuyod jsotuyod changed the title [VF] - NEW Salesforce VisualForce language support [vf] New Salesforce VisualForce language support Mar 7, 2017
jsotuyod added a commit to jsotuyod/pmd that referenced this pull request Mar 7, 2017
@jsotuyod
Update changelog, refs pmd#279
4338c71
@sgorbaty
sgorbaty deleted the VFSupport branch April 13, 2017 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jsotuyod jsotuyod jsotuyod left review comments
@adangel adangel adangel left review comments

Uh oh!

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

Assignees

@jsotuyod jsotuyod

Labels

a:new-language Proposal to add a new PMD or CPD language to the main distribution a:new-rule Proposal to add a new built-in rule

Projects

None yet

Milestone

5.6.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

@sgorbaty @jsotuyod @rsoesemann @adangel @sergeygorbaty
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.