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

Add disallowJavaScriptCode rule #114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

patriksimek
Copy link

@patriksimek patriksimek commented Sep 22, 2016

This PR adds a new rule to disallow usage of JavaScript inside a template. This is useful in situations when Pug is used as lightweight markup language but allowing access to code is not desirable.

For me Pug mixed with Markdown filter is the most comfortable way to create static HTML documents, like rich documentation. This rule should prevent the possibility to insert malicious code.

I read the docs twice, but I'm not 100% sure if I covered all the places where JavaScript can be included.

@codecov-io
Copy link

codecov-io commented Sep 22, 2016

Current coverage is 100% (diff: 100%)

Merging #114 into master will not change coverage

@@           master   #114   diff @@
====================================
  Files          49     50     +1   
  Lines         915    921     +6   
  Methods         0      0          
  Messages        0      0          
  Branches        0      0          
====================================
+ Hits          915    921     +6   
  Misses          0      0          
  Partials        0      0          

Powered by Codecov. Last update eb60b36...62f1e7c

@TimothyGu
Copy link
Member

Instead of just disabling all JavaScript, would you prefer to use something like constantinople to only error out on non-constant JS expressions?

@patriksimek
Copy link
Author

In my case I would prefer to disable javascript completly.

@TimothyGu
Copy link
Member

@patriksimek, I mean, what you are doing right now is what constantinople does, but imperfectly with three regexes (!(/^-?\d*\.?\d*$/.test(token.val) || /^"(?:[^"\\]|\\.)*"$/.test(token.val) || /^'(?:[^'\\]|\\.)*'$/.test(token.val))) instead of a proper parser.

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

Successfully merging this pull request may close these issues.

None yet

3 participants