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 +4 -4
- data/README.md +56 -19
- data/app/controllers/dbviewer/application_controller.rb +8 -4
- data/lib/dbviewer/configuration.rb +2 -1
- data/lib/dbviewer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 648be97f775ec9c5d18dabf9ebe90e164d760fde2b1e3c9c9ff2442eb6dba9fe
|
4
|
+
data.tar.gz: f0510fd50eabd5ba176d99e9dd3b66d074d1ccaf6cf15aa43a82beec0e45e923
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
228
|
+
### Basic Authentication
|
214
229
|
|
215
|
-
|
230
|
+
You can enable HTTP Basic Authentication to secure access to DBViewer:
|
216
231
|
|
217
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
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
|
-
|
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
|
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 :
|
6
|
+
before_action :authenticate_with_basic_auth
|
7
7
|
before_action :set_tables
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
def
|
12
|
-
unless
|
13
|
-
|
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
|
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
|
data/lib/dbviewer/version.rb
CHANGED