ruby_native 0.2.5 → 0.2.6

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
  SHA256:
3
- metadata.gz: bc155ab038d88ddb0029ce9072f91ec0728249a388aa3fcc1e8ccc2ce2af7d78
4
- data.tar.gz: 150029c5dd6f61b13e0fb0d097bfb61ab2048f259c536fe17048b1908025b716
3
+ metadata.gz: ad18c6fcb69bcf375a6a44ef5513e47d6ff96dbf1957636d2fc964a9a124a078
4
+ data.tar.gz: '048a44c3fa9f59016d8dad8f60f2e2d8330a403285ede35541465162eb64c11e'
5
5
  SHA512:
6
- metadata.gz: f943b32f452f9cc638ae3332cbe62ceeb166cc2ad7e9df9d8272c24836dce4bdfb2f7c3a6e4e897ed7d9cd076bb92626ab3772a9a0ac649869d8d7fb1a4cdf13
7
- data.tar.gz: 6988fe9f67885859619b1217ffe86e1bf829fcf0b67996cfd49017a7de4a2337356b9253857479fdc3a2e0d90bf0396c581110c3676c265ec6e51117f99ce77e
6
+ metadata.gz: 03c531fb7b9739e8744493e41024b6472ad43d43ef287686fec672ab1ddda186c9ad4463d86a4844ce0b2d35f5c1cf6ddf89075c2998e3f8d6d4727be7fcdf77
7
+ data.tar.gz: dd6f724b78af89ac07c72ea9b5acc898af580a1042d822bab3cf948eb9e577124dbaecbcb43342ff095a890b0055a8152d5a8a1a93a87960e9be86651e51ca12
@@ -6,6 +6,7 @@ appearance:
6
6
  tint_color: "#007AFF"
7
7
  background_color: "#FFFFFF"
8
8
  status_bar_color: "#F8F9FA"
9
+ # edge_to_edge: true # Let the web view extend behind the status bar (Normal Mode only)
9
10
  # Dark mode example (replace the plain strings above):
10
11
  # background_color:
11
12
  # light: "#FFFFFF"
@@ -32,6 +32,12 @@ module RubyNative
32
32
  app.middleware.insert_before ActionDispatch::Cookies, RubyNative::OAuthMiddleware
33
33
  end
34
34
 
35
+ initializer "ruby_native.tunnel_cookie_middleware" do |app|
36
+ if Rails.env.development?
37
+ app.middleware.insert_before ActionDispatch::Cookies, RubyNative::TunnelCookieMiddleware
38
+ end
39
+ end
40
+
35
41
  initializer "ruby_native.routes" do |app|
36
42
  app.routes.prepend do
37
43
  mount RubyNative::Engine, at: "/native"
@@ -0,0 +1,45 @@
1
+ module RubyNative
2
+ # Strips the `domain=` attribute from Set-Cookie headers when the request
3
+ # comes through a Cloudflare tunnel (*.trycloudflare.com).
4
+ #
5
+ # Many Rails apps configure `domain: :all, tld_length: 2` on their session
6
+ # store. Through a tunnel this resolves to `.trycloudflare.com`, a public
7
+ # suffix domain. Browsers and WKWebView silently reject those cookies,
8
+ # breaking authentication.
9
+ #
10
+ # Removing the domain attribute lets the cookie scope to the exact tunnel
11
+ # hostname (e.g. `abc-123.trycloudflare.com`) so it persists normally.
12
+ class TunnelCookieMiddleware
13
+ TUNNEL_HOST_PATTERN = /\.trycloudflare\.com\z/
14
+
15
+ def initialize(app)
16
+ @app = app
17
+ end
18
+
19
+ def call(env)
20
+ status, headers, body = @app.call(env)
21
+
22
+ if tunnel_request?(env) && headers["set-cookie"]
23
+ strip_cookie_domain!(headers)
24
+ end
25
+
26
+ [status, headers, body]
27
+ end
28
+
29
+ private
30
+
31
+ def tunnel_request?(env)
32
+ host = env["HTTP_HOST"] || env["SERVER_NAME"] || ""
33
+ host.match?(TUNNEL_HOST_PATTERN)
34
+ end
35
+
36
+ def strip_cookie_domain!(headers)
37
+ raw = headers["set-cookie"]
38
+ cookies = raw.is_a?(Array) ? raw : raw.split("\n")
39
+
40
+ headers["set-cookie"] = cookies.map { |cookie|
41
+ cookie.gsub(/;\s*domain=[^;]*/i, "")
42
+ }.join("\n")
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyNative
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
data/lib/ruby_native.rb CHANGED
@@ -4,6 +4,7 @@ require "ruby_native/native_version"
4
4
  require "ruby_native/native_detection"
5
5
  require "ruby_native/inertia_support"
6
6
  require "ruby_native/oauth_middleware"
7
+ require "ruby_native/tunnel_cookie_middleware"
7
8
  require "ruby_native/engine"
8
9
 
9
10
  module RubyNative
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Masilotti
@@ -79,6 +79,7 @@ files:
79
79
  - lib/ruby_native/native_detection.rb
80
80
  - lib/ruby_native/native_version.rb
81
81
  - lib/ruby_native/oauth_middleware.rb
82
+ - lib/ruby_native/tunnel_cookie_middleware.rb
82
83
  - lib/ruby_native/version.rb
83
84
  homepage: https://github.com/Ruby-Native/gem
84
85
  licenses: