Skip to content

Commit fc0202d

Browse files
authored
Add configuration option for verifying client browser (#144)
1 parent b318912 commit fc0202d

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@
7777
- [Prevent Controller Action](#prevent-controller-action)
7878
- [Broadcasting Turbo Streams](#broadcasting-turbo-streams)
7979
- [State](#state)
80-
- [Ephemeral Page State](#ephemeral-page-state)
80+
- [Server Side State](#server-side-state)
81+
- [Client Side State](#client-side-state)
82+
- [Data Binding](#data-binding)
83+
- [State Resolution](#state-resolution)
84+
- [Page State](#page-state)
8185
- [Community](#community)
8286
- [Developing](#developing)
8387
- [Notable Files](#notable-files)
@@ -206,14 +210,17 @@ TurboBoost::Commands.config.tap do |config|
206210
# opt-[in/out] of precompiling TurboBoost assets (*true, false)
207211
config.precompile_assets = true
208212

209-
# opt-[in/out] of forgery protection (true, *false)
213+
# opt-[in/out] of forgery protection (*true, false)
210214
config.protect_from_forgery = true
211215

212216
# opt-[in/out] of raising an error when an invalid command is invoked (true, false, *"development", "test", "production")
213217
config.raise_on_invalid_command = "development"
214218

215219
# opt-[in/out] of state resolution (true, *false)
216220
config.resolve_state = true
221+
222+
# opt-[in/out] of verifying the client browser (*true, false)
223+
config.verify_client = true
217224
end
218225
```
219226

@@ -529,9 +536,23 @@ _Learn more about Turbo Stream broadcasting by reading through the
529536
530537
## State
531538

532-
TODO: Document state tracking
539+
### Server Side State
540+
541+
TODO
542+
543+
### Client Side State
544+
545+
TODO
546+
547+
### Data Binding
548+
549+
TODO
550+
551+
### State Resolution
552+
553+
TODO
533554

534-
### Ephemeral Page State
555+
### Page State
535556

536557
You can opt-in to remember transient page state when using Rails tag helpers with `turbo_boost[:remember]` to track
537558
element attribute values between requests.

lib/turbo_boost/commands/engine.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ class Engine < ::Rails::Engine
2525
config.turbo_boost_commands[:alert_on_abort] = false # (true, false, "development", "test", "production")
2626
config.turbo_boost_commands[:alert_on_error] = false # (true, false, "development", "test", "production")
2727
config.turbo_boost_commands[:precompile_assets] = true # (true, false)
28-
config.turbo_boost_commands[:protect_from_forgery] = false # (true, false) TODO: Support override in Commands
28+
config.turbo_boost_commands[:protect_from_forgery] = true # (true, false)
2929
config.turbo_boost_commands[:raise_on_invalid_command] = "development" # (true, false, "development", "test", "production")
3030
config.turbo_boost_commands[:resolve_state] = false # (true, false)
31+
config.turbo_boost_commands[:verify_client] = true # (true, false)
3132

3233
initializer "turbo_boost_commands.configuration", before: :build_middleware_stack do |app|
3334
Mime::Type.register "text/vnd.turbo-boost.html", :turbo_boost

lib/turbo_boost/commands/middlewares/entry_middleware.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def mime_type
3333
# @param request [Rack::Request] the request to check
3434
# @return [Boolean]
3535
def trusted_client?(request)
36+
return true unless TurboBoost::Commands.config.verify_client
3637
client = DeviceDetector.new(request.env["HTTP_USER_AGENT"])
3738
return false unless client.known?
3839
return false if client.bot?

test/dummy/config/initializers/turbo_boost.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
# - alert_on_abort, opt-(in/out) of alerting on abort (true, *false, "development", "test", "production")
1414
# - alert_on_error, opt-(in/out) of alerting on error (true, *false, "development", "test", "production")
1515
# - precompile_assets, opt-(in/out) of precompiling assets (*true, false)
16-
# - protect_from_forgery, opt-(in/out) of forgery protection (true, *false)
16+
# - protect_from_forgery, opt-(in/out) of forgery protection (*true, false)
1717
# - raise_on_invalid_command, opt-(in/out) of raising an error if invalid command requested (true, false, *"development", "test", "production")
1818
# - resolve_state, opt-(in/out) of state resolution (true, *false)
19+
# - verify_client, opt-(in/out) of verifying the client browser (*true, false)
1920
#
2021
TurboBoost::Commands.config.tap do |config|
2122
config.alert_on_abort = "development"
@@ -24,4 +25,5 @@
2425
config.protect_from_forgery = true
2526
config.raise_on_invalid_command = "development"
2627
config.resolve_state = false
28+
config.verify_client = true
2729
end

0 commit comments

Comments
 (0)