Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Query your logs using good old ActiveRecord.
Add this line to your application's Gemfile:
gem 'queryable_logs'
And then execute:
$ bundle
Or install it yourself as:
$ gem install queryable_logs
Run
rails g queryable_logs
.
This will generate a migration file.
class CreateTrailLogs < ActiveRecord::Migration
def change
create_table :trail_logs do |t|
t.integer :user_id
t.string :ip_address
t.string :controller
t.string :action
t.string :format
t.string :http_verb
t.text :params_hash
t.datetime :logged_at
t.string :response_code
t.string :request_url
t.string :sig
t.timestamps null: false
end
end
end
and an initializer file.
class Trail
cattr_accessor :current_user_method, :logger, :saving_logs
LogFile = Rails.root.join('log', 'trail.log')
delegate :debug, :info, :warn, :error, :fatal, :to => :logger
end
Trail.logger = Logger.new(Trail::LogFile)
Trail.logger.level = 'info' # could be debug, info, warn, error or fatal
Trail.current_user_method = :current_user
queryable_logs also logs the current user id. Let the gem know which method you are using to get the current user. Default is set to current_user
.
Finally, include the QueryableLogs::WriteLog
in the base controller, typically the ApplicationController
.
class ApplicationController < ActionController::Base
include QueryableLogs::WriteLog
end
Enter the following task to your crontab rake parse:logs_to_db
eg: 0 * * * * cd /Users/akshaytakkar/sample_rails_app && /Users/akshaytakkar/.rvm/wrappers/ruby-3.1.0/rake db:parse_log_and_save_trails >> /Users/akshaytakkar/sample_rails_app/log/worker.log 2>&1
This will run the rake parse:logs_to_db
rake task every hour and log any errors or output from the task to worker.log
file.
Use QueryableLogs::TrailLog
like any ActiveRecord object.
eg: query how many requests you got for the posts
controller index
action. QueryableLogs::TrailLog.where(controller: 'posts', action: 'index').count
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the QueryableLogs project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that queryable_logs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.