Socket
Book a DemoInstallSign in
Socket

cheap_coder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheap_coder

0.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

CheapCoder

The CheapCoder gem can censor Ruby scripts.

This allows only non-structed scripts which do not contain any shell command.

Usage

The sample code below provides a script samples/sample1.rb rejected any built-in methods, e.g. puts and == (received by a constant).

require 'cheap_coder'
require 'parser/current'

CODEPATH = 'samples/sample1.rb'

expr = Parser::CurrentRuby.parse(File.read(CODEPATH))
censor = CheapCoder::Censor.new
expr = censor.process(expr)
puts Unparser.unparse(expr)

The censor rejects also any shell commands. For example, please see the censord result of samples/sample2.rb.

Whitelist

One can set a whitelist of methods. The sample below provides a script admits the build-in puts.

method_whitelist = %i[puts]
censor = CheapCoder::Censor.new(
  allowed_methods: method_whitelist,
)
expr = censor.process(expr)

Evaluator

One can set an evaluator to a censor instance. For example, the below evaluates the ABC size metric (not strictly).

censor = CheapCoder::Censor.new(
  evaluator: CheapCoder::AbcEvaluator.new
)
censor.process(expr)
censor.score # gives ABC size

FAQs

Package last updated on 04 Aug 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.