
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Execute Javascript in the browser from the server using WebSockets.
This is a proof of concept. There are no attempts to secure this feature or even make it practical in a multi-user environment. That's right, any browser that is viewing the site is going to get the same javascript executed on it. This gem should really only ever be used in development.
The original use for this was to send all logs to browser as it was appended.
def pipe_to_browser(src)
File.open(src,"r") do |f|
f.seek(0,IO::SEEK_END)
while true do
IO.select([f]) # wait for change
line = f.gets
Socket2me.exec_js "$('#logs').append(#{line.to_json})"
end
end
end
Thread.new{pipe_to_browser('log/development.log')}
Please don't run this in production. Ever.
Add this line to your application's Gemfile:
group :development, :test do
gem 'socket2me'
end
And then execute:
$ bundle
Or install it yourself as:
$ gem install socket2me
A full rack example is in examples/dummy.ru
. That app simply creates
an HTML page and provides a helper js function to display some output. The
example then outputs the server time every second in a background thread.
To run examples/dummy.ru
:
git clone https://github.com/ddrscott/socket2me
cd socket2me
./bin/setup
rackup examples/dummy.ru
# config.ru
use SocketToMe::Middleware::AddScriptTag
# config/environments/development.rb
config.middleware.use SocketToMe::Middleware::AddScriptTag
# elsewhere.rb
SocketToMe.exec_js "alert('hello world!')"
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Spot check everything works by running rackup examples/dummy.ru
. The browser
should continually append a timestamp below the header.
Bug reports and pull requests are welcome on GitHub at https://github.com/ddrscott/socket2me.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that socket2me 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
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.