dbviewer 0.3.4 → 0.3.5

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: c368abfe3b3131b1df3b3234e1e560c2cb5f715c035680d3848ff5ff07d99cc3
4
- data.tar.gz: 7f9b27e43d86b0181f14d9deceebcb1d6624b22cb51885ab5c3b929814cb97f9
3
+ metadata.gz: 648be97f775ec9c5d18dabf9ebe90e164d760fde2b1e3c9c9ff2442eb6dba9fe
4
+ data.tar.gz: f0510fd50eabd5ba176d99e9dd3b66d074d1ccaf6cf15aa43a82beec0e45e923
5
5
  SHA512:
6
- metadata.gz: 05f35000d4c57ec2e17e0c0fe56d49520add9f0c061debc25f5f6407ec1e52ece7a1d4361c0b92d283135492bc78d86890083e9781a30705ebcddc0fce2e58df
7
- data.tar.gz: a76035a207c87105f9331dc4246a133da9941a5a9e435133b80254fc0037578bc69b5dbb17cb40113049ba50625d3a81816df118015446af8e9c368127e481c9
6
+ metadata.gz: 84bdca42e27ed6dbcf2dfdcdb2756558796b0e2ecc727fa46ffe7fd734bf66d21d5fd76c47d9ae632a003292048c78151a412fcc98c6b33954d2f23cd7b71c19
7
+ data.tar.gz: 9f1204704614413b211b1814c96660656e03579712015152b3323f9dff0d64caaff5b96017cbbe203ed9a77ce15bc23e0e1d9473143edca14824f1380b925a25
data/README.md CHANGED
@@ -87,13 +87,24 @@ Rails.application.routes.draw do
87
87
  # Your application routes...
88
88
 
89
89
  # Mount the DBViewer engine
90
- if Rails.env.development?
91
- mount Dbviewer::Engine, at: "/dbviewer"
92
- end
90
+ mount Dbviewer::Engine, at: "/dbviewer"
91
+ # The engine can be mounted in any environment when using Basic Authentication
92
+ end
93
+ ```
94
+
95
+ Configure Basic Authentication in an initializer to secure access (strongly recommended):
96
+
97
+ ```ruby
98
+ # config/initializers/dbviewer.rb
99
+ Dbviewer.configure do |config|
100
+ config.admin_credentials = {
101
+ username: "your_username",
102
+ password: "your_secure_password"
103
+ }
93
104
  end
94
105
  ```
95
106
 
96
- Then, visit `/dbviewer` in your browser to access the database viewer.
107
+ Then, visit `/dbviewer` in your browser to access the database viewer. You'll be prompted for your username and password.
97
108
 
98
109
  ### Rails API-only Applications
99
110
 
@@ -171,6 +182,9 @@ Dbviewer.configure do |config|
171
182
  config.query_logging_mode = :memory # Storage mode for SQL queries (:memory or :file)
172
183
  config.query_log_path = "log/dbviewer.log" # Path for query log file when in :file mode
173
184
  config.max_memory_queries = 1000 # Maximum number of queries to store in memory
185
+
186
+ # Authentication options
187
+ config.admin_credentials = { username: "admin", password: "your_secure_password" } # Basic HTTP auth credentials
174
188
  end
175
189
  ```
176
190
 
@@ -209,37 +223,60 @@ DBViewer includes several security features to protect your database:
209
223
  - **Query Limits**: Automatic LIMIT clause added to prevent excessive data retrieval
210
224
  - **Pattern Detection**: Detection of SQL injection patterns and suspicious constructs
211
225
  - **Error Handling**: Informative error messages without exposing sensitive information
226
+ - **HTTP Basic Authentication**: Protect access with username and password authentication
212
227
 
213
- ## 🌱 Production Access (Not Recommended)
228
+ ### Basic Authentication
214
229
 
215
- By default, DBViewer only runs in development or test environments for security reasons. If you need to access it in production (not recommended):
230
+ You can enable HTTP Basic Authentication to secure access to DBViewer:
216
231
 
217
- 1. Set an environment variable with a secure random key:
232
+ ```ruby
233
+ Dbviewer.configure do |config|
234
+ config.admin_credentials = {
235
+ username: "your_username",
236
+ password: "your_secure_password"
237
+ }
238
+ end
239
+ ```
218
240
 
219
- ```
220
- DBVIEWER_PRODUCTION_ACCESS_KEY=your_secure_random_key
221
- ```
241
+ When credentials are provided, all DBViewer routes will be protected by HTTP Basic Authentication.
242
+ Without valid credentials, users will be prompted for a username and password before they can access any DBViewer page.
222
243
 
223
- 2. Add an additional constraint in your routes:
244
+ ## 🌱 Production Access
245
+
246
+ With the addition of Basic Authentication, DBViewer can now be used in any environment including production. We recommend the following for production deployments:
247
+
248
+ 1. **Always** enable HTTP Basic Authentication with strong credentials:
224
249
 
225
250
  ```ruby
226
- if Rails.env.production?
227
- constraints ->(req) { req.params[:access_key] == ENV["DBVIEWER_PRODUCTION_ACCESS_KEY"] } do
228
- mount Dbviewer::Engine, at: "/dbviewer"
229
- end
230
- else
231
- mount Dbviewer::Engine, at: "/dbviewer"
251
+ Dbviewer.configure do |config|
252
+ config.admin_credentials = {
253
+ username: "unique_username",
254
+ password: SecureRandom.hex(16) # Generate a strong random password
255
+ }
232
256
  end
233
257
  ```
234
258
 
235
- 3. Access the tool with the override parameter:
259
+ 2. Mount the engine in your routes file:
260
+
261
+ ```ruby
262
+ # In any environment, with Basic Auth protection
263
+ mount Dbviewer::Engine, at: "/dbviewer"
264
+ ```
265
+
266
+ 3. Access the tool through your regular application URL:
236
267
  ```
237
268
  https://yourdomain.com/dbviewer?override_env_check=your_secure_random_key
238
269
  ```
239
270
 
240
271
  ## 📝 Security Note
241
272
 
242
- ⚠️ **Warning**: This engine is designed for development purposes. It's not recommended to use it in production as it provides direct access to your database contents. If you must use it in production, ensure it's protected behind authentication and use the production access key mechanism with a strong random key.
273
+ ⚠️ **Warning**: This engine provides direct access to your database contents, which contains sensitive information. Always protect it with HTTP Basic Authentication by configuring strong credentials as shown above.
274
+
275
+ When used in production, ensure:
276
+
277
+ - You use long, randomly generated passwords (e.g., with `SecureRandom.hex(16)`)
278
+ - You access DBViewer over HTTPS connections only
279
+ - Access is limited to trusted administrators only
243
280
 
244
281
  ## 🤌🏻 Contributing
245
282
 
@@ -3,14 +3,18 @@ module Dbviewer
3
3
  include Dbviewer::DatabaseOperations
4
4
  include Dbviewer::ErrorHandling
5
5
 
6
- before_action :ensure_development_environment
6
+ before_action :authenticate_with_basic_auth
7
7
  before_action :set_tables
8
8
 
9
9
  private
10
10
 
11
- def ensure_development_environment
12
- unless Rails.env.development? || Rails.env.test? || params[:override_env_check] == ENV["DBVIEWER_PRODUCTION_ACCESS_KEY"]
13
- render plain: "DBViewer is only available in development and test environments for security reasons.", status: :forbidden
11
+ def authenticate_with_basic_auth
12
+ return unless Dbviewer.configuration.admin_credentials.present?
13
+
14
+ credentials = Dbviewer.configuration.admin_credentials
15
+ authenticate_or_request_with_http_basic("DBViewer Authentication") do |username, password|
16
+ ActiveSupport::SecurityUtils.secure_compare(username, credentials[:username]) &
17
+ ActiveSupport::SecurityUtils.secure_compare(password, credentials[:password])
14
18
  end
15
19
  end
16
20
 
@@ -31,7 +31,8 @@ module Dbviewer
31
31
  # Maximum number of queries to keep in memory
32
32
  attr_accessor :max_memory_queries
33
33
 
34
- # Admin access credentials (username, password)
34
+ # Admin access credentials hash with :username and :password keys
35
+ # @example { username: 'admin', password: 'secret' }
35
36
  attr_accessor :admin_credentials
36
37
 
37
38
  def initialize
@@ -1,3 +1,3 @@
1
1
  module Dbviewer
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbviewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wailan Tirajoh