Configuring ShieldJS
  • 26 Dec 2024
  • 2 Minutes à lire
  • Sombre
    Lumière
  • PDF

Configuring ShieldJS

  • Sombre
    Lumière
  • PDF

The content is currently unavailable in French. You are viewing the default English version.
Résumé de l’article

ShieldJS has quite a comprehensive configuration system which includes a built-in default configuration or a configuration loaded from a file, either of which can be overridden with command line options, for convenience.

The default configuration looks like this:

{
  /* Use a random seed */
  "seed": 0,

  /* Create a sourcemap for each protected file */
  "sourcemaps": {
    "enabled": false,
    "outputPath": ""
  },

  /* How to treat files */
  "files": [
    {
      /* Optional: a meaningful name for this config group */
      "name": "default",

      /* files included in this spec */
      "filter": [ "*.js" ],

      /* Protection settings for these files */
      "renaming": { "enabled": true, "globals": false, "utf": false },
      "integrityChecking": { "enabled": true, "callback": "", "failSilent": false, "checkFrequency": 0.1 },
      "propertyHiding": { "enabled": true },
      "externalsHiding": { "enabled": true, "globals": false },
      "stringHiding": { "enabled": true, "maxLength": 1024 },
      "integerHiding": { "enabled": true },
      "operatorRemoval": { "enabled": true },
      "antiDebug": { "enabled": true },
      "functionShuffling": { "enabled": true }
    }
  ]
}

The configuration is structured to allow for different protection settings for different groups of files. The files are matched by the filter attribute within each file group. If multiple groups match a particular file then the first matching group is used, meaning the order in which they are defined is important. Each group also has a name attribute which is displayed in the output as each file is processed so you can confirm that the match is to the group you intended.

Filter rules processing

The file matching filter makes use of a rule processing system to determine what is in scope or not. The rules are specified as a JSON array of strings. The strings are processed from left to right adding or subtracting values to the set. The set starts empty and the following characters are important:

! subtract, patterns starting with an exclamation mark are removed from the set. Patterns that don’t start with an exclamation mark are added to the set.

* wildcard, match anything.

Examples

Pattern

Function

["*"]

Add all available files to the set

["*.js"]

Add everything ending with .js

["*","!vendor.js"]

Everything except vendor.js

["index.js"]

Just index.js

["index.js","lib.js"]

index.js and lib.js

["index.js", "!*"]

Add index.js and then remove everything i.e. nothing

["*.js","!debug_*"]

All .js files except any prefixed with debug_

Command line overrides

If a config file is used from the command line using the -f option but additional command line options are used to e.g. --rename-globals then this will override the option in the config file and for all file groups. This allows for easy debugging so you can disable or change various options without having to change the base configuration.


Cet article vous a-t-il été utile ?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Ozzy, facilitant la découverte de connaissances grâce à l’intelligence conversationnelle