force_unspecified 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5238ca184400b2297278b1ee44b237707841302ce6e27f543810dab18f3d76a
4
+ data.tar.gz: afa97181e9da5501cb87d32311dab831d8835553b0a4c3a4da3b30cd1cf9ae35
5
+ SHA512:
6
+ metadata.gz: 9f96aa12756cc77d6723a283cccb441927138dbde5003d4352b4eecd1a14909b488fbb949d5782512ebcad43b903a50331b781082bb2cb108ff017d8389c5596
7
+ data.tar.gz: c7605a705e189bd1fb44710883f648b060720cbad6ac7d248bf49b862bd364e61d54c2a417ed8c6f5bd4910c3aa1068c0db50f134b6ae2b1b33a49ca5fe248cd
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in force_unspecified.gemspec
6
+ gemspec
7
+
8
+ gem 'puma'
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ force_unspecified (0.1.0)
5
+ rack
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ puma (3.11.0)
11
+ rack (2.0.3)
12
+ rake (12.3.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler
19
+ force_unspecified!
20
+ puma
21
+ rake
22
+
23
+ BUNDLED WITH
24
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Sorah Fukumori
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.
@@ -0,0 +1,41 @@
1
+ # ForceUnspecified: Rack app redirects to a SAML IdP URL with changing NameIDPolicy Format in SAMLRequest to unspecified
2
+
3
+ - Before: `<samlp:NameIDPolicy AllowCreate='true' Format='urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'/>`
4
+ - After: `<samlp:NameIDPolicy AllowCreate='true' Format='urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified'/>`
5
+
6
+ Some IdP, e.g. Azure Active Directory, forces user's _true_ identifier even if an admin set customized User Identifier to the IdP, when a SAML request comes with `NameIDPolicy` Format=`emailAddress`. This is a simple Rack app that replaces all policies to `unspecified` before passing to IdP.
7
+
8
+ ## Installation
9
+
10
+ ```ruby
11
+ # Gemfile
12
+ gem 'force_unspecified'
13
+ ```
14
+
15
+ ```ruby
16
+ # config.ru
17
+ require 'force_unspecified'
18
+ run ForceUnspecified
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ 1. Set your RP to use `https://force_unspecified/ORIGINAL_URL` as a IdP SAML URL.
24
+ - (where `force_unspecified` is your deployment URL of this app, and `ORIGINAL_URL` is your original IdP SAML URL)
25
+ - e.g. `https://force_unspecified/https://login.example.org/SAML`
26
+ 2. When RP sends a user to this app, this app changes `nameid-format` to `unspecified`, then redirects to the IdP.
27
+ 3. Happiness
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sorah/force_unspecified.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "force_unspecified"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require 'force_unspecified'
2
+
3
+ run ForceUnspecified::App
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "force_unspecified/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "force_unspecified"
8
+ spec.version = ForceUnspecified::VERSION
9
+ spec.authors = ["Sorah Fukumori"]
10
+ spec.email = ["sorah@cookpad.com"]
11
+
12
+ spec.summary = %q{Rack app redirects to a SAML IdP URL with changing NameIdPolicy in SAMLRequest to unspecified}
13
+ spec.homepage = "https://github.com/sorah/force_unspecified"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "rack"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,8 @@
1
+ require "force_unspecified/version"
2
+ require "force_unspecified/app"
3
+
4
+ module ForceUnspecified
5
+ def self.call(env)
6
+ App.call(env)
7
+ end
8
+ end
@@ -0,0 +1,63 @@
1
+ require 'rack'
2
+ require 'zlib'
3
+
4
+ module ForceUnspecified
5
+ class App
6
+ def self.call(env)
7
+ new(env).call
8
+ end
9
+
10
+ def initialize(env)
11
+ @request = Rack::Request.new(env)
12
+ end
13
+
14
+ attr_reader :request
15
+
16
+ def call
17
+ next_hop = URI.decode_www_form_component(request.path.sub(%r{^/}, ''))
18
+ if next_hop.empty?
19
+ return index()
20
+ end
21
+ unless saml_request_original
22
+ return [400, {'Content-Type' => 'text/plain'}, ["SAMLRequest is missing\n"]]
23
+ end
24
+
25
+ modified_saml_request = saml_request.
26
+ gsub(/(['"])urn:oasis:names:tc:SAML:1.1:nameid-format:.+?(["'])/, '\1urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\2')
27
+ param = encode_saml_request(modified_saml_request)
28
+
29
+ [302, {'Location' => "#{next_hop}?SAMLRequest=#{param}"}, ['']]
30
+ end
31
+
32
+ def index
33
+ [200, {'Content-Type' => 'text/plain'}, [<<-EOF]]
34
+ https://github.com/sorah/force_unspecified
35
+ Modifies received SAMLRequest to force 'unspecified' as a requested NameIDPolicy, and redirects to a SAML consumer URL.
36
+
37
+ Usage: #{request.base_url}/https://login.example.org/saml?SAMLRequest=xxxxx
38
+ EOF
39
+ end
40
+
41
+ def saml_request_original
42
+ request.params['SAMLRequest']
43
+ end
44
+
45
+ def decode_saml_request
46
+ return nil unless saml_request_original
47
+ decoded = saml_request_original.unpack('m*')[0]
48
+ begin
49
+ Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(decoded)
50
+ rescue
51
+ decoded
52
+ end
53
+ end
54
+
55
+ def encode_saml_request(string = saml_request())
56
+ URI.encode_www_form_component [Zlib::Deflate.deflate(string, 9)[2..-5]].pack('m*').gsub(/\r?\n/, '')
57
+ end
58
+
59
+ def saml_request
60
+ @saml_request ||= decode_saml_request
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module ForceUnspecified
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: force_unspecified
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sorah Fukumori
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
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: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - sorah@cookpad.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - config.ru
71
+ - force_unspecified.gemspec
72
+ - lib/force_unspecified.rb
73
+ - lib/force_unspecified/app.rb
74
+ - lib/force_unspecified/version.rb
75
+ homepage: https://github.com/sorah/force_unspecified
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.7.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Rack app redirects to a SAML IdP URL with changing NameIdPolicy in SAMLRequest
99
+ to unspecified
100
+ test_files: []