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

Updates from josh-lauer #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ task "fixtures", "Generate .coffee fixtures from .eco fixtures", ->
task "dist", "Generate dist/eco.js", ->
build -> bundle ->
fs = require("fs")
coffee = require("coffee-script").compile
coffee = require("coffeescript").compile
uglify = require("uglify-js")

read = (filename) ->
Expand All @@ -58,9 +58,9 @@ task "dist", "Generate dist/eco.js", ->
"./scanner": read "lib/scanner.js"
"./util": read "lib/util.js"
"strscan": read "node_modules/strscan/lib/strscan.js"
"coffee-script": stub "CoffeeScript"
"coffeescript": stub "CoffeeScript"

package = for name, source of modules
cake_package = for name, source of modules
"""
'#{name}': function(module, require, exports) {
#{source}
Expand All @@ -77,7 +77,10 @@ task "dist", "Generate dist/eco.js", ->
*/
"""

source = uglify """
minify = (code) ->
uglify.minify(code).code

source = minify """
this.eco = (function(modules) {
return function require(name) {
var fn, module = {id: name, exports: {}};
Expand All @@ -89,12 +92,12 @@ task "dist", "Generate dist/eco.js", ->
}
};
})({
#{package.join ',\n'}
#{cake_package.join ',\n'}
})('eco');
"""

try
fs.mkdirSync "#{__dirname}/dist", 0755
fs.mkdirSync "#{__dirname}/dist", 755
catch err

fs.writeFileSync "#{__dirname}/dist/eco.js", "#{header}\n#{source}"
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
## This is a modified version of eco that depends on underscore.js for a safer `_.escape`

**Why?** Because Eco's default `__escape` implementation doesn't escape single quotes, which makes XSS attacks like the following possible:

```html
<input type='text' value='<%= @value %>'>
```

with a @value of `x'onmouseover='alert(document.domain)`, an XSS occurs.

### How to use this fork

Use `dist/eco.js` instead of the unmaintained eco.js

### How to use this fork with Rails and the eco gem

Copy `dist/eco.js` into `vendor/assets/javascripts/eco-custom.js` and add the following to your application.rb file:

```ruby
class Application < Rails::Application
...
# Eco, the Coffee Script templating language, hasn't been updated in 3 years. We found an XSS bug in the escape
# function and fixed it by forking the library and using underscore.js's implementation. In order to avoid also
# having to fork the eco Ruby gem, we're setting an explicit override path to our updated eco.js.
ENV['ECO_SOURCE_PATH'] = Rails.root.join("vendor/assets/javascripts/eco-custom.js").to_s
end
```

Run `rm -rf tmp/cache/` to clear your local asset pipeline cache and restart your local Rails app. Double check the fix
by looking at application.js and searching for `__escape`.

### How to recompile

Compile with: `cake dist`

Eco: Embedded CoffeeScript templates
====================================

Expand Down
105 changes: 70 additions & 35 deletions lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/compiler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions lib/preprocessor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading