Git Product home page Git Product logo

solium-plugin-security's Introduction

The official Security Plugin for Ethlint (formerly Solium)

Build Status

This Plugin provides security-focused lint rules for Ethlint (formerly Solium).

The rules have been taken from Consensys' Recommended Smart Contract Practices and Solium's Rule Wishlist.

Installation

NOTE: If you're using Solium v1.0.1 or above, this plugin comes pre-installed as a local dependency and you can skip this section.

npm install -g solium-plugin-security

Usage

NOTE: If you've installed Solium v1.0.1 or above and created soliumrc.json using solium --init, you can skip this step since solium automatically applies the security plugin for you.

Add security to your soliumrc.json's plugins array. Your configuration file should look like:

{
    "extends": "solium:all",
    "plugins": ["security"],
    "rules": {
        ...
    }
}

List of rules

Below are the rules supplied by this plugin and the information on passing options to them and their auto-fixing capabilities.

Some of them aren't always desirable and are therefore disabled by default (marked below as OFF). You should explicitly enable them in your .soliumrc.json.

Name Description Options Defaults Fixes Default Setting
no-throw Discourage use of throw statement for error flagging YES ENABLED
no-tx-origin Discourage use of tx.origin global variable ENABLED
enforce-explicit-visibility Encourage user to explicitly specify visibility of function YES ENABLED
no-block-members Discourage use of members blockhash & timestamp (and alias now) of block global variable List of members to warn against ["blockhash", "timestamp"] ENABLED
no-call-value Discourage use of .call.value()() ENABLED
no-assign-params Disallow assigning to function parameters ENABLED
no-fixed Disallow fixed point types ENABLED
no-inline-assembly Discourage use of inline assembly ENABLED
no-low-level-calls Discourage the use of low-level functions - call(), callcode() & delegatecall() List of functions to warn against ["call", "callcode", "delegatecall"] ENABLED
no-modify-for-iter-var Discourage user to modify a for loop iteration counting variable in the loop body ENABLED
no-send Discourage the use of unsafe method send() ENABLED
no-sha3 Encourage use of keccak256() over sha3() function YES ENABLED
no-unreachable-code Disallow unreachable code ENABLED
check-send-result Enforce checking the result of send() call ENABLED
else-after-elseif Encourage user to use else statement after else-if statement DISABLED
enforce-loop-bounds Encourage use of loops with fixed bounds DISABLED
enforce-placeholder-last Enforce that the function placeholder is the last statement in the modifier DISABLED
return-at-end Discourage use of early returns in functions DISABLED
one-break-per-loop Discourage use of multiple breaks in while/for/do loops DISABLED
max-statements-in-func Enforce upper limit on number of statements inside a function Maximum number of statements 25 DISABLED
no-abstract-func Discourage use of abstract functions DISABLED
no-bit-operations Disallow bitwise operations DISABLED
no-continue Discourage use of continue statement DISABLED
no-inheritance Discourage use of inheritance Disallow interface inheritance { "no-interface": false } DISABLED
no-multiple-inheritance Discourage use of multiple inheritance Disallow interface inheritance { "no-interface": false } DISABLED
no-named-params Disallow named function parameters DISABLED
no-named-returns Discourage use of named returns in functions DISABLED
256-bit-ints-only Disallow non-256 bit integers DISABLED
no-suicide-or-selfdestruct Disallow suicide and selfdestruct DISABLED
no-var Disallow type deduction via var DISABLED
no-user-defined-modifiers Disallow user-defined modifiers DISABLED
no-void-returns Discourage use of void returns in functions prototypes DISABLED
no-func-overriding Discourage function overriding DISABLED

An example soliumrc.json configuring and applying this plugin is:

{
    "plugins": ["security"],
    "rules": {
        "some-other-solium-rule": 1,
        "security/no-low-level-calls": ["error", ["call", "delegatecall"]],
        "security/no-block-members": [1, ["timestamp"]],
        "security/no-throw": "off"
    }
}

This tells solium to apply the 3 security/ rules with special configuration provided and apply the remaining rules of the plugin with their default configurations. If you want to disable a plugin rule, you have to explicitly disable it inside rules.

Lint normally using solium -d contracts/ or solium -d contracts/ --fix to apply fixes as well.

Developer Setup

  • git clone <URL-of-this-repo>
  • cd solium-plugin-security
  • npm install --dev
  • npm link
  • npm link solium-plugin-security
  • npm test

If you'd also like to use your develop build of this plugin with dev build of Solium, go to Solium's directory and run npm link solium-plugin-security. This will let Solium access your modified plugin instead of its pre-installed security module.

See developing a plugin.

Known Issues

  1. When installing the Linter from the ethlint NPM package, you might see the following warning:
npm WARN [email protected] requires a peer of solium@^1.0.0 but none is installed. You must install peer dependencies yourself.

You can safely ignore this warning.

Solium was recently renamed to Ethlint and the linter is available for download from both solium and ethlint NPM packages. Ethlint comes shipped with this Security plugin. This plugin checks to ensure whether solium NPM package is installed or not.

There is currently no way in NPM to allow any one of the specified packages to satisfy as peer dependency, so we can't specify solium OR ethlint. We also cannot change solium to ethlint in peerDependencies because its a potential breaking change. See the original issue.

solium-plugin-security's People

Contributors

beaugunderson avatar cisplatin avatar come-maiz avatar mitchellvanderhoeff avatar mpokrass avatar nfeignon avatar tristanh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

solium-plugin-security's Issues

Error on new security rules

If I try to use one of the newer security rules I get an error when running Solium:

โœ– [Fatal error] - An error occurred while linting over /home/alex/Work/augur-core/source/contracts/Augur.sol: An error occured while trying to load rules: Unable to load Plugin "solium-plugin-securtiy"

This is when I include something like

"securtiy/else-after-elseif": "error",

when using solium 1.0.9

Question concerning rules to enable

Hi,

I was wondering how you specify that you want to activate all the security rules (enabled and disabled rules by default) in .soliumrc.json file?

Cycl0pe

npm test causing SyntaxError

After running npm install --dev (which works fine), I run npm test and get the following:

~/Projects/solium-plugin-security (master) $ npm test

> [email protected] test /Users/Cisplatin/Projects/solium-plugin-security
> mocha --require should --reporter spec --recursive

npm /Users/Cisplatin/Projects/solium-plugin-security/test/index.js:18
		const { meta, rules } = SoliumSecurityPlugin;
		      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at /Users/Cisplatin/Projects/solium-plugin-security/node_modules/mocha/lib/mocha.js:231:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/Cisplatin/Projects/solium-plugin-security/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/Users/Cisplatin/Projects/solium-plugin-security/node_modules/mocha/lib/mocha.js:514:10)
    at Object.<anonymous> (/Users/Cisplatin/Projects/solium-plugin-security/node_modules/mocha/bin/_mocha:484:18)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:142:18)
    at node.js:939:3
npm ERR! Test failed.  See above for more details.

This is running node v5.9.0

npm warning requiring peer of solium

When installing ethlint you get a npm warning message:

npm WARN [email protected] requires a peer of solium@^1.0.0 but none is installed. You must install peer dependencies yourself.

I expect this is because solium has now been renamed to ethlint, but this project still lists solium as a peer dependency

  "peerDependencies": {
    "solium": "^1.0.0"
  },

https://github.com/duaraghav8/solium-plugin-security/blob/master/package.json#L29-L31

I'm happy to open a PR to address this, but I'm not super familiar with how peerDependencies work.

I think ideally it'd specify that it could have a peer depednecy of solium@^1.0.0 OR ethlint@^1.0.0?

Keeping track of Bounty Rules

https://github.com/AugurProject/augur-bounties
(Rules that have either already been merged or their PR is now ready and about to be merged have been checked)
Note that some rules were already part of this plugin before the bounty was released, so nobody has initiated PRs for them.

  • [required] Prohibit function overriding
  • [required] Enforce function prototype to have a return type
  • [optional] Functions must have a single return at the end of the function
  • [required] Prohibit modification of for loop iteration counting variables in the loop body
  • [required] Prohibit loops without fixed bounds
  • [required] Functions must have an explicit return statement
  • [required] Prohibit abstract functions
  • [required] Prohibit use of inheritance
  • [required] Prohibit use of multiple inheritance
  • [required] Prohibit use of send
  • [required] An else clause must be included after else if
  • [optional] Prohibit use of user-defined modifiers
  • [required] Prohibit unreachable code
  • [required] Prohibit use of var / all variable types must be explicitly stated
  • [required] Prohibit use of tx.origin
  • [required] Prohibit use of continue statement
  • [required] Prohibit use of selfdestruct/suicide
  • [required] Prohibit use of integer types smaller than 256 bits
  • [required] Prohibit use of assembly
  • [required] Prohibit use of named parameters in function calls.
  • [required] Prohibit fixedpoint (fixed and ufixed) types
  • [optional] Prohibit use of call.value
  • [required] Prohibit bitshifts and bit operators
  • [optional] Restrict functions to a user-specified number of lines of code
  • [required] Only one break statement allowed per loop

TODO

  • Improve no-assign-params message to point out the exact param that's being modified instead of just mentioning function name
  • Refine no-explicit-visibility rule.
  • Coverage
  • Tests for remaining rules (that are in prod in v0.2.0) + package.json tests (just like in Solium)
  • README: add augur bounty in description "these rules have been taken from..."
  • Fully document how #25 has been resolved
  • Travis ensure success
  • Add Augur & all bounty participants' name in docs (under community section)
  • remove list-of-rules.tgn
  • run eslint - standardize indentation, quotes, bracketing, etc.
  • Arrange rules alphabetically in readme, index.js etc (if necessary)

Types of refinement to be done

  • Renaming
  • refactoring of rule implementations
  • recommended = true/false
  • type (default severity or switched off) (duaraghav8/Ethlint#142)
  • more automated tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.