puppet-validator 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a8844ff2f61370de5412e932959747fa2f6c0a5
4
- data.tar.gz: d9737a5ccd70a93cdcc4505d50fb5806b6a6d317
3
+ metadata.gz: c3dc256dd81faa824703173a618ee04e5744afa2
4
+ data.tar.gz: 6beb62e29d7b8b49bb2441b0e9414cdae0dd3760
5
5
  SHA512:
6
- metadata.gz: d9dbbae1c479485c6d4fb67d1a25567187c432092f6753ac1a7e51fd0adc07020c7c0a2151300e5f1deb3a5116b4b0b374614096507ae0e2addb72cb0f54d13e
7
- data.tar.gz: 9d6833e36e27f4dc18d60ef31234a35251cb9bec346a01876933905c8da44c1baa469ddb26906ac7db6ae6bc6a4fbd13128d51e65b5857ddd0f4dd8892045581
6
+ metadata.gz: 9270323f2c725c7389883ca0f2c180132b4074b9fee02401b9a64a0bae35fd9e2bc2753b1700aecc3b0e3b1fcc564b6e15f06107e146c30d96683fc07fbfc646
7
+ data.tar.gz: 728b48f8044fe6e9703212eeb79a997543e1b49d339da39887f810598e4aba28a735bd5f107497422e1f1b5355489dd7acd05a710122ea9bceaca6a4d0c3e86c
data/README.md CHANGED
@@ -259,3 +259,9 @@ A simple `systemd` init script might look something like:
259
259
 
260
260
  Customize the command line as needed. You might include a `--theme` or `--port`
261
261
  argument, or you might provide the full path to an `rvm` installed gem.
262
+
263
+ ### Bookmarklet
264
+
265
+ If you just want to validate Puppet code you see on a website, follow the
266
+ instructions on http://binford2k.com/content/2016/06/puppetlinter-dot-com
267
+
@@ -5,6 +5,9 @@ require 'puppet'
5
5
  require 'puppet/parser'
6
6
  require 'puppet-lint'
7
7
 
8
+ require 'nokogiri'
9
+ require 'cgi'
10
+
8
11
  # something like 3,000 lines of code
9
12
  MAXSIZE = 100000
10
13
  CONTEXT = 3
@@ -13,9 +16,17 @@ class PuppetValidator < Sinatra::Base
13
16
  set :logging, true
14
17
  set :strict, true
15
18
 
16
- before {
19
+ enable :sessions
20
+
21
+ before do
17
22
  env["rack.logger"] = settings.logger if settings.logger
18
- }
23
+
24
+ session[:csrf] ||= SecureRandom.hex(32)
25
+ response.set_cookie 'authenticity_token', {
26
+ :value => session[:csrf],
27
+ :expires => Time.now + (60 * 60 * 24),
28
+ }
29
+ end
19
30
 
20
31
  def initialize(app=nil)
21
32
  super(app)
@@ -68,6 +79,15 @@ class PuppetValidator < Sinatra::Base
68
79
  logger.info "Validating code from #{request.ip}."
69
80
  logger.debug "validating #{request.ip}: #{params['code']}"
70
81
 
82
+ halt 403, 'Request validation failed.' unless safe?
83
+
84
+ frag = Nokogiri::HTML.fragment(params['code'])
85
+ unless frag.elements.empty?
86
+ logger.warn 'HTML code found in validation string'
87
+ frag.elements.each { |elem| logger.debug "HTML: #{elem.to_s}" }
88
+ params['code'] = CGI.escapeHTML(params['code'])
89
+ end
90
+
71
91
  if request.body.size <= MAXSIZE
72
92
  result = validate params['code']
73
93
  lint = lint(params['code'], params['checks']) if params['lint'] == 'on'
@@ -109,6 +129,15 @@ class PuppetValidator < Sinatra::Base
109
129
 
110
130
  helpers do
111
131
 
132
+ def safe?
133
+ if session[:csrf] == params['_csrf'] && session[:csrf] == request.cookies['authenticity_token']
134
+ true
135
+ else
136
+ logger.warn 'CSRF attempt detected.'
137
+ false
138
+ end
139
+ end
140
+
112
141
  def validate(data)
113
142
  begin
114
143
  Puppet.settings[:app_management] = true if Gem::Version.new(Puppet.version) >= Gem::Version.new('4.3.2')
@@ -53,7 +53,7 @@ function popup(title, text, url) {
53
53
  buttons: {
54
54
  Ok: function () {
55
55
  $(this).dialog("close");
56
- $("#dlg").remove();
56
+ $("#popup").remove();
57
57
  }
58
58
  }
59
59
  });
@@ -10,6 +10,7 @@
10
10
  <h1>Puppet Code Validator</h1>
11
11
  <p>Paste Puppet code into the following textbox and check it for validity.</p>
12
12
  <form action="/validate" method="post">
13
+ <input name="_csrf", type="hidden" value="<%= session[:csrf] %>" />
13
14
  <div class="entry">
14
15
  <textarea name="code" id="code" cols="65" rows="25"></textarea>
15
16
  <input type="submit" value="Validate" id="validate">
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Ford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -58,6 +58,26 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.1'
61
+ - !ruby/object:Gem::Dependency
62
+ name: nokogiri
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.6'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.6.5
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.6'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.6.5
61
81
  description: |2
62
82
  Puppet Validator is a simple web service that accepts arbitrary code submissions and
63
83
  validates it the way `puppet parser validate` would. It can optionally also
@@ -68,13 +88,11 @@ executables:
68
88
  extensions: []
69
89
  extra_rdoc_files: []
70
90
  files:
71
- - README.md
72
91
  - LICENSE
73
- - config.ru
92
+ - README.md
74
93
  - bin/puppet-validator
94
+ - config.ru
75
95
  - lib/puppet-validator.rb
76
- - views/index.erb
77
- - views/result.erb
78
96
  - public/gist.png
79
97
  - public/info.png
80
98
  - public/prism-default.css
@@ -82,8 +100,11 @@ files:
82
100
  - public/scripts.js
83
101
  - public/styles.css
84
102
  - public/testing.html
103
+ - views/index.erb
104
+ - views/result.erb
85
105
  homepage: https://github.com/puppetlabs/puppet-validator/
86
- licenses: []
106
+ licenses:
107
+ - Apache-2.0
87
108
  metadata: {}
88
109
  post_install_message:
89
110
  rdoc_options: []
@@ -101,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
122
  version: '0'
102
123
  requirements: []
103
124
  rubyforge_project:
104
- rubygems_version: 2.0.14.1
125
+ rubygems_version: 2.6.10
105
126
  signing_key:
106
127
  specification_version: 4
107
128
  summary: Puppet code validator as a service