/

Available Protections

ByteHide Shield provides multiple layers of protection to secure your JavaScript code. This page provides a reference for all the protection options available in Shield.

Core Protection Types

Shield's protections are grouped into the following categories:

1. Code Transformations

These protections change the structure and flow of your code to make it difficult to understand.

ProtectionDescriptionDefault
Control Flow FlatteningTransforms the control flow of your code into a state machine formatDisabled
Dead Code InjectionAdds meaningless code that's difficult to distinguish from real codeDisabled
Split StringsSplits string literals into chunks to hide their meaningDisabled
Numbers to ExpressionsConverts numeric literals to complex expressionsDisabled
Object TransformationsObfuscates object keys and property access patternsDisabled

2. String Protection

These protections specifically target string literals in your code.

ProtectionDescriptionDefault
String ArrayMoves string literals to a special array and replaces them with referencesEnabled
String EncodingApplies various encoding algorithms to strings in the string arrayNone
Unicode EscapesConverts strings to unicode escape sequencesDisabled

3. Identifier Protection

These protections focus on variable, function, and parameter names.

ProtectionDescriptionDefault
Identifier RenamingRenames local variables, function names, and parametersHexadecimal
Property RenamingRenames object properties throughout your codeDisabled
Identifier PrefixAdds a custom prefix to all renamed identifiersNone

4. Anti-Debug Protections

These protections prevent debugging and tampering with your code.

ProtectionDescriptionDefault
Self DefendingMakes code resistant against modifications and formattingDisabled
Debug ProtectionPrevents using browser debugging toolsDisabled
Console DisableDisables console logging statementsDisabled
Domain LockRestricts code execution to specific domainsNone

Protection Presets

Shield offers predefined presets to quickly configure multiple protections:

PresetDescription
defaultBalanced protection with minimal performance impact
OptimizedBasic protection focusing on speed and compatibility
BalanceBalanced protection suitable for most applications
MaximumMaximum protection with increased code size and complexity

Use a preset by setting the optionsPreset field:

{
  "optionsPreset": "balance"
}

You can also extend presets with your own custom options:

{
  "optionsPreset": "balance",
  "domainLock": ["example.com"],
  "selfDefending": true
}

Protection Compatibility

Not all protections can be used together. Here are some important compatibility notes:

  1. Self Defending is incompatible with source maps and pretty-formatted code
  2. Control Flow Flattening can significantly increase code size
  3. Debug Protection with interval may affect performance
  4. Property Renaming in unsafe mode may break your application if not configured carefully

Performance Considerations

Protections have different impacts on performance, bundle size, and load time:

High Impact

  • Control Flow Flattening
  • Dead Code Injection
  • Debug Protection with Interval

Medium Impact

  • String Array with multiple encoding layers
  • Property Renaming
  • Self Defending

Low Impact

  • Identifier Renaming
  • String Array (basic)
  • Domain Lock
  • Console Disable

Protection Strategy

For the best balance of security and performance, consider this layered approach:

  1. For all code:

    • Basic identifier renaming
    • String Array protection
  2. For sensitive functions:

    • Control Flow Flattening (with moderate threshold)
    • String Encoding (preferably base64)
    • Numbers to Expressions
  3. For production only:

    • Self Defending
    • Debug Protection
    • Domain Lock (if applicable)

Configuration Examples

Basic Protection

{
  "compact": true,
  "controlFlowFlattening": false,
  "deadCodeInjection": false,
  "stringArray": true,
  "stringArrayEncoding": ["base64"],
  "identifierNamesGenerator": "hexadecimal"
}

Maximum Protection

{
  "compact": true,
  "controlFlowFlattening": true,
  "controlFlowFlatteningThreshold": 0.7,
  "deadCodeInjection": true,
  "deadCodeInjectionThreshold": 0.4,
  "stringArray": true,
  "stringArrayEncoding": ["rc4"],
  "stringArrayThreshold": 0.8,
  "stringArrayIndexShift": true,
  "selfDefending": true,
  "identifierNamesGenerator": "hexadecimal",
  "numbersToExpressions": true,
  "debugProtection": true,
  "renameProperties": true,
  "renamePropertiesMode": "safe",
  "transformObjectKeys": true
}

Balanced Approach

{
  "compact": true,
  "controlFlowFlattening": true,
  "controlFlowFlatteningThreshold": 0.5,
  "deadCodeInjection": false,
  "stringArray": true,
  "stringArrayEncoding": ["base64"],
  "stringArrayThreshold": 0.75,
  "selfDefending": false,
  "identifierNamesGenerator": "hexadecimal",
  "numbersToExpressions": false,
  "debugProtection": true,
  "domainLock": ["example.com"]
}

Next Steps

Previous
API