should_send_same_site_none 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/gem-push.yml +43 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/should_send_same_site_none.rb +101 -0
- data/lib/should_send_same_site_none/version.rb +3 -0
- data/should_send_same_site_none.gemspec +25 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 65f77bd6e0e4b8fe411ef768d2aa5217f4e837c04f06fe863585f06e08e70978
|
4
|
+
data.tar.gz: 41a0842f509515e9e29685ef0e5768a990497fa1d185a9edf05be710dee62438
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44ae07b8191260f6d2d2b1059681b9f8c14634d509a7091d2e6de424ed56ae4f925d1f27e8ce9b513e077b7125b9c95583b5c0e3f2cf65ea710d373b663477e6
|
7
|
+
data.tar.gz: 7e2c4175df286d870f9a3f4dfd2871e5dbcf23e752f7339b22605985f51851a788f5483d758045e76e666a065e5aa7697f6da5cf93fb81c75b758aa469e0a423
|
@@ -0,0 +1,43 @@
|
|
1
|
+
name: Ruby Gem CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
inputs:
|
6
|
+
distTag:
|
7
|
+
description: 'Dist tag to publish'
|
8
|
+
required: true
|
9
|
+
default: 'latest'
|
10
|
+
push:
|
11
|
+
branches: [ master ]
|
12
|
+
pull_request:
|
13
|
+
branches: [ master ]
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
build:
|
17
|
+
name: Build + Publish
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
- name: Set up Ruby 2.6
|
23
|
+
uses: actions/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: 2.6.x
|
26
|
+
|
27
|
+
- name: Test
|
28
|
+
run: |
|
29
|
+
gem install bundler
|
30
|
+
bundle install
|
31
|
+
rake spec
|
32
|
+
|
33
|
+
- name: Publish to RubyGems
|
34
|
+
if: ${{github.event.inputs.distTag == 'latest'}}
|
35
|
+
run: |
|
36
|
+
mkdir -p $HOME/.gem
|
37
|
+
touch $HOME/.gem/credentials
|
38
|
+
chmod 0600 $HOME/.gem/credentials
|
39
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
40
|
+
gem build *.gemspec
|
41
|
+
gem push *.gem
|
42
|
+
env:
|
43
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at smoreno@finametrix.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
should_send_same_site_none (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
rake (12.3.3)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.2)
|
16
|
+
rspec-support (~> 3.9.3)
|
17
|
+
rspec-expectations (3.9.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
rake (~> 12.0)
|
30
|
+
rspec (~> 3.0)
|
31
|
+
should_send_same_site_none!
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Sergio
|
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,58 @@
|
|
1
|
+
![Ruby Gem CI](https://github.com/semoal/should_send_same_site_none/workflows/Ruby%20Gem%20CI/badge.svg?branch=master)
|
2
|
+
# ShouldSendSameSiteNone
|
3
|
+
|
4
|
+
With this gem you can check a user-agent is compatible with `SameSite:none` cookie.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'should_send_same_site_none'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install should_send_same_site_none
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
This gem was originally created to check on Ruby on Rails redis session store, if we can pass same_site or not for ex:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# redis-action-pack gem
|
28
|
+
def set_cookie(env, _session_id, cookie)
|
29
|
+
request = wrap_in_request(env)
|
30
|
+
if (request.user_agent.present? && ShouldSendSameSiteNone.is_same_site_compatible(value))
|
31
|
+
if (cookie[:same_site].present? && cookie[:same_site] == :none)
|
32
|
+
cookie.delete(:same_site)
|
33
|
+
end
|
34
|
+
cookie_jar(request)[key] = cookie.merge(cookie_options)
|
35
|
+
else
|
36
|
+
cookie_jar(request)[key] = cookie.merge(cookie_options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
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.
|
44
|
+
|
45
|
+
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).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/should_send_same_site_none. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/should_send_same_site_none/blob/master/CODE_OF_CONDUCT.md).
|
50
|
+
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
55
|
+
|
56
|
+
## Code of Conduct
|
57
|
+
|
58
|
+
Everyone interacting in the ShouldSendSameSiteNone project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/should_send_same_site_none/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "should_send_same_site_none"
|
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,101 @@
|
|
1
|
+
require "should_send_same_site_none/version"
|
2
|
+
|
3
|
+
module ShouldSendSameSiteNone
|
4
|
+
class Error < StandardError; end
|
5
|
+
def self.is_same_site_compatible(user_agent)
|
6
|
+
return !is_compatible(user_agent.to_s)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def self.is_compatible(user_agent)
|
12
|
+
return (
|
13
|
+
has_webkit_bug(user_agent) || drops_unrecognized_same_site(user_agent)
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.has_webkit_bug(user_agent)
|
18
|
+
return (
|
19
|
+
is_ios_version(12, user_agent) ||
|
20
|
+
(is_macosx_version(10, 14, user_agent) &&
|
21
|
+
(is_safari(user_agent) || is_mac_embedded_browser(user_agent)))
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.drops_unrecognized_same_site(user_agent)
|
26
|
+
return (
|
27
|
+
(is_chromium_based(user_agent) &&
|
28
|
+
is_chromium_version_at_least(51, user_agent) &&
|
29
|
+
!is_chromium_version_at_least(67, user_agent)) ||
|
30
|
+
(is_uc_browser(user_agent) && !is_uc_browser_version_at_least(12, 13, 2, user_agent))
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.is_ios_version(major, user_agent)
|
35
|
+
regex = /\(iP.+; CPU .*OS (\d+)[_\d]*.*\) AppleWebKit\//
|
36
|
+
# Extract digits from first capturing group.
|
37
|
+
extract_regex_match(user_agent, regex, 1) == major.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.is_macosx_version(major, minor, user_agent)
|
41
|
+
regex = /\(Macintosh;.*Mac OS X (\d+)_(\d+)[_\d]*.*\) AppleWebKit\//
|
42
|
+
extract_regex_match(user_agent, regex, 1) == major.to_s && extract_regex_match(user_agent, regex, 2) == minor.to_s
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.is_safari(user_agent)
|
46
|
+
safari_regex = /Version\/.* Safari\//
|
47
|
+
user_agent.match(safari_regex) != nil && !is_chromium_based(user_agent)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.is_mac_embedded_browser(user_agent)
|
51
|
+
regex = /^Mozilla\/[\.\d]+ \(Macintosh;.*Mac OS X [_\d]+\) AppleWebKit\/[\.\d]+ \(KHTML, like Gecko\)$/
|
52
|
+
regex_contains(user_agent, regex)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.is_chromium_based(user_agent)
|
56
|
+
regex = /Chrom(e|ium)/
|
57
|
+
regex_contains(user_agent, regex)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.is_chromium_version_at_least(major, user_agent)
|
61
|
+
regex = /Chrom[^ \/]+\/(\d+)[\.\d]* /
|
62
|
+
version = extract_regex_match(user_agent, regex, 1).to_i
|
63
|
+
return version >= major
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.is_uc_browser(user_agent)
|
67
|
+
regex = /UCBrowser\//
|
68
|
+
regex_contains(user_agent, regex)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.is_uc_browser_version_at_least(major, minor, build, user_agent)
|
72
|
+
regex = /UCBrowser\/(\d+)\.(\d+)\.(\d+)[\.\d]* /
|
73
|
+
major_version = extract_regex_match(user_agent, regex, 1).to_i
|
74
|
+
minor_version = extract_regex_match(user_agent, regex, 2).to_i
|
75
|
+
build_version = extract_regex_match(user_agent, regex, 3).to_i
|
76
|
+
if (major_version == major)
|
77
|
+
return major_version > major
|
78
|
+
end
|
79
|
+
|
80
|
+
if (minor_version != minor)
|
81
|
+
return minor_version > minor
|
82
|
+
end
|
83
|
+
|
84
|
+
return build_version >= build
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.extract_regex_match(string_value, regex, offsetIndex)
|
88
|
+
matches = string_value.match(regex) unless string_value.nil?
|
89
|
+
|
90
|
+
if (matches != nil && matches[offsetIndex] != nil)
|
91
|
+
return matches[offsetIndex]
|
92
|
+
end
|
93
|
+
|
94
|
+
return nil
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.regex_contains(string_value, regex)
|
98
|
+
matches = string_value.match(regex) unless string_value.nil?
|
99
|
+
return matches != nil
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'lib/should_send_same_site_none/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "should_send_same_site_none"
|
5
|
+
spec.version = ShouldSendSameSiteNone::VERSION
|
6
|
+
spec.authors = ["Sergio"]
|
7
|
+
spec.email = ["sergiomorenoalbert@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{A simple utility to detect incompatible user agents for `SameSite=None` cookie attribute}
|
10
|
+
spec.description = %q{A simple utility to detect incompatible user agents for `SameSite=None` cookie attribute}
|
11
|
+
spec.homepage = "https://github.com/semoal/should_send_same_site_none"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: should_send_same_site_none
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergio
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple utility to detect incompatible user agents for `SameSite=None`
|
14
|
+
cookie attribute
|
15
|
+
email:
|
16
|
+
- sergiomorenoalbert@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".github/workflows/gem-push.yml"
|
22
|
+
- ".gitignore"
|
23
|
+
- ".rspec"
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- bin/console
|
31
|
+
- bin/setup
|
32
|
+
- lib/should_send_same_site_none.rb
|
33
|
+
- lib/should_send_same_site_none/version.rb
|
34
|
+
- should_send_same_site_none.gemspec
|
35
|
+
homepage: https://github.com/semoal/should_send_same_site_none
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata:
|
39
|
+
homepage_uri: https://github.com/semoal/should_send_same_site_none
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.0.3
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: A simple utility to detect incompatible user agents for `SameSite=None` cookie
|
59
|
+
attribute
|
60
|
+
test_files: []
|