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

UnderscoreJS output escaping improvement? #345

Closed
GaryJones opened this issue Jan 14, 2019 · 9 comments · Fixed by #595
Closed

UnderscoreJS output escaping improvement? #345

GaryJones opened this issue Jan 14, 2019 · 9 comments · Fixed by #595

Comments

@GaryJones
Copy link
Contributor

The Underscorejs output escaping sniff checks for <%=, but it's possible that <%= _.escape(...) would also sufficiently escape the output.

I don't know UnderscoreJS, so this needs looking into, but it may help remove some false positives.

@mikeyarce
Copy link
Member

@GaryJones GaryJones modified the milestones: 2.2.0, 2.3.0 Jul 27, 2020
@jrfnl jrfnl added the JS/CSS label Oct 7, 2020
@jrfnl
Copy link
Collaborator

jrfnl commented Oct 14, 2020

I would love to have some more code samples for this to work with.

I also noticed that the sniff is supposed to check both PHP as well as JS files, but doesn't have a JS test file, so code samples from both would be very very welcome!!!

@GaryJones
Copy link
Contributor Author

Example of what should not raise a violation:

function display_foo {
?>
	<script id="template" type="text/template">
		<li class="dashboard-post-item" dashboard-id="<%= _.escape( id ) %>">
			<div class="image-wrapper">
				<img src="<%= _.escape( image_url ) %>" class="dashboard-image">
			</div>
			...
		</li>
	</script>
<?php
}

@jrfnl
Copy link
Collaborator

jrfnl commented Oct 19, 2020

I've done a file search on WPDirectory to find some more code samples and noticed that the <%= marker which is searched for, often is used in gruntfile.js. While that file should normally not be deployed, should I make an exception in the code to not trigger on <%= without escaping if the file in which it is found is gruntfile.js ?

@jrfnl
Copy link
Collaborator

jrfnl commented Oct 20, 2020

Question: Undescorejs also supports the normal JS (unsafe) print function`, like so:

var compiled = _.template("<% print('Hello ' + epithet); %>");

Should this sniff try to detect that as well ?

@jrfnl
Copy link
Collaborator

jrfnl commented Oct 21, 2020

@rebeccahum @GaryJones Your input on the above two questions would be much appreciated.

@GaryJones
Copy link
Contributor Author

While that file should normally not be deployed, should I make an exception in the code to not trigger on <%= without escaping if the file in which it is found is gruntfile.js

We could probably exclude gruntfile.js (in the root of the repo, or root of the theme, or root of a plugin?) for all checks. So for this particular check, yes please to excluding it.

Should this sniff try to detect that as well ?

Yes please.

@jrfnl
Copy link
Collaborator

jrfnl commented Oct 25, 2020

We could probably exclude gruntfile.js (in the root of the repo, or root of the theme, or root of a plugin?) for all checks

We could add an <exclude-pattern> to the ruleset for this, though a generically re-usable ruleset should normally not include <exclude-pattern>s.
In that case, no sniff specific changed would be needed. All the same, it's easy enough to address in the sniff itself.

@rebeccahum
Copy link
Contributor

Should this sniff try to detect that as well ?

Echoing Gary, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants