safe_uri 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/safe_uri/exceptions.rb +4 -0
- data/lib/safe_uri/open-uri.rb +31 -0
- data/lib/safe_uri/version.rb +3 -0
- data/lib/safe_uri.rb +9 -0
- data/safe_uri.gemspec +30 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5020c28e3147e307c5f5c0f4724b51fa1c73dbff05f2fe7088b18cca51f850bd
|
4
|
+
data.tar.gz: 500fdcb4d323fb6c82186e6a56ef61af894aa1d63777638a35db876f53e042c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5720d70c0fd94b8b855deea5c355fb91b21f0711b5c2acb6937336edc904ca97d154806313633a5c27d491f13411c401c9486650f54318c2f43d19e75f36ff93
|
7
|
+
data.tar.gz: b63699cf84fb5b6f2ec74d560a7d4e730552b519346c733725d73336153732c70e51a9f2b55160ef9be0a2a26da82a6cca271a57f55e3aad3e490ebd628a7469
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
safe_uri (0.1.0)
|
5
|
+
addressable
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.6.0)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
public_suffix (3.0.3)
|
14
|
+
rake (10.5.0)
|
15
|
+
rspec (3.8.0)
|
16
|
+
rspec-core (~> 3.8.0)
|
17
|
+
rspec-expectations (~> 3.8.0)
|
18
|
+
rspec-mocks (~> 3.8.0)
|
19
|
+
rspec-core (3.8.0)
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-expectations (3.8.2)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-mocks (3.8.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-support (3.8.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 2.0)
|
34
|
+
rake (~> 10.0)
|
35
|
+
rspec (~> 3.0)
|
36
|
+
safe_uri!
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Koji Onishi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# SafeURI
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/safe_uri`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'safe_uri'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install safe_uri
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/safe_uri.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "safe_uri"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module SafeURI
|
2
|
+
# Kernel.open、URI.open is vulnerable to command injection if pipe charactor '|' is given as input.
|
3
|
+
# https://docs.ruby-lang.org/en/2.6.0/Kernel.html#method-c-open
|
4
|
+
# https://docs.rubocop.org/en/latest/cops_security/#securityopen
|
5
|
+
# This occurs as open-uri delegates its #open method to Kernel#open, while overriding Kernel#open.
|
6
|
+
# #open below provides safer alternative to URI.open equivalent.
|
7
|
+
# raises exception when pipe charactor is specified (usually Errno::ENOENT)
|
8
|
+
def self.open(url, *args, **options)
|
9
|
+
|
10
|
+
parsed_url = parse_url(url)
|
11
|
+
if parsed_url.scheme
|
12
|
+
if parsed_url.respond_to?(:open)
|
13
|
+
parse_url(url).open(*args, **options)
|
14
|
+
else
|
15
|
+
raise UnsupportedScheme.new, "scheme #{parsed_url.scheme} is not supported by open-uri"
|
16
|
+
end
|
17
|
+
else
|
18
|
+
# avoid falling back to Kernel.open
|
19
|
+
File.open(url, *args, **options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.parse_url(url)
|
24
|
+
# To percent-encode multi-byte charactors (that might be included as part of given url)
|
25
|
+
# SafeURI relies on Addressable::URI#normalize that can handle proper encoding
|
26
|
+
# while avoiding double-encoding when percent-encoded charactors already exists.
|
27
|
+
normalized_url = Addressable::URI.parse(url).normalize.to_s
|
28
|
+
URI.parse(normalized_url)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/lib/safe_uri.rb
ADDED
data/safe_uri.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "safe_uri/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "safe_uri"
|
8
|
+
spec.version = SafeURI::VERSION
|
9
|
+
spec.authors = ["Koji Onishi"]
|
10
|
+
spec.email = ["fursich0@gmail.com"]
|
11
|
+
spec.required_ruby_version = '>= 2.3.0'
|
12
|
+
|
13
|
+
spec.summary = %q{a simple, safe alternative for URI.#open and Kernel.#open. With SafeURI.open you are not affected by pipe character injection that potentailly leads to various vulnerabilities.}
|
14
|
+
spec.description = %q{SafeURI is an alternative implementation that allows you to open an URI with safer approach - with SafeURI.#open, you can always force to use URI.parse(url).open, or File.open(filename) depending on the provided argument. The pipe character '|' is NOT accepted as it does not delegate to Kernel.#open (falls back to File.#open), unlike URI.#open that falls back to Kernel.#open when un-openable arguments are given.}
|
15
|
+
spec.homepage = 'https://github.com/fursich/safe_uri'
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "addressable"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: safe_uri
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koji Onishi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: SafeURI is an alternative implementation that allows you to open an URI
|
70
|
+
with safer approach - with SafeURI.#open, you can always force to use URI.parse(url).open,
|
71
|
+
or File.open(filename) depending on the provided argument. The pipe character '|'
|
72
|
+
is NOT accepted as it does not delegate to Kernel.#open (falls back to File.#open),
|
73
|
+
unlike URI.#open that falls back to Kernel.#open when un-openable arguments are
|
74
|
+
given.
|
75
|
+
email:
|
76
|
+
- fursich0@gmail.com
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- ".gitignore"
|
82
|
+
- ".rspec"
|
83
|
+
- ".travis.yml"
|
84
|
+
- Gemfile
|
85
|
+
- Gemfile.lock
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- bin/console
|
90
|
+
- bin/setup
|
91
|
+
- lib/safe_uri.rb
|
92
|
+
- lib/safe_uri/exceptions.rb
|
93
|
+
- lib/safe_uri/open-uri.rb
|
94
|
+
- lib/safe_uri/version.rb
|
95
|
+
- safe_uri.gemspec
|
96
|
+
homepage: https://github.com/fursich/safe_uri
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.3.0
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubygems_version: 3.0.1
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: a simple, safe alternative for URI.#open and Kernel.#open. With SafeURI.open
|
119
|
+
you are not affected by pipe character injection that potentailly leads to various
|
120
|
+
vulnerabilities.
|
121
|
+
test_files: []
|