Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change Log

v2.15.1
---
* **Hotfix**: `domainDest` => `domainLockRedirectUrl` option rename

v2.15.0
---
* Added `domainDest` option that option allows the browser to be redirected to a passed domain if the source code isn't run on the domains or URL specified by `domainLock`. Thank you https://github.com/erikdubbelboer!
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Following options are available for the JS Obfuscator:
debugProtectionInterval: false,
disableConsoleOutput: false,
domainLock: [],
domainDest: 'about:blank',
domainLockRedirectUrl: 'about:blank',
forceTransformStrings: [],
identifierNamesCache: null,
identifierNamesGenerator: 'hexadecimal',
Expand Down Expand Up @@ -422,7 +422,7 @@ Following options are available for the JS Obfuscator:
--debug-protection-interval <boolean>
--disable-console-output <boolean>
--domain-lock '<list>' (comma separated)
--domain-dest <string>
--domain-lock-redirect-url <string>
--exclude '<list>' (comma separated)
--force-transform-strings '<list>' (comma separated)
--identifier-names-cache-path <string>
Expand Down Expand Up @@ -690,17 +690,17 @@ Type: `string[]` Default: `[]`

Allows to run the obfuscated source code only on specific domains and/or sub-domains. This makes really hard for someone to just copy and paste your source code and run it elsewhere.

If the source code isn't run on the domains specified by this option, the browser will be redirected to a passed to the [`domainDest`](#domaindest) option domain or URL.
If the source code isn't run on the domains specified by this option, the browser will be redirected to a passed to the [`domainLockRedirectUrl`](#domainlockredirecturl) option URL.

##### Multiple domains and sub-domains
It's possible to lock your code to more than one domain or sub-domain. For instance, to lock it so the code only runs on **www.example.com** add `www.example.com`. To make it work on the root domain including any sub-domains (`example.com`, `sub.example.com`), use `.example.com`.

### `domainDest`
### `domainLockRedirectUrl`
Type: `string` Default: `about:blank`

##### :warning: This option does not work with `target: 'node'`

Allows the browser to be redirected to a passed domain or URL if the source code isn't run on the domains specified by [`domainLock`](#domainlock)
Allows the browser to be redirected to a passed URL if the source code isn't run on the domains specified by [`domainLock`](#domainlock)

### `exclude`
Type: `string[]` Default: `[]`
Expand Down
2 changes: 1 addition & 1 deletion dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "2.15.0",
"version": "2.15.1",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand Down
4 changes: 2 additions & 2 deletions src/cli/JavaScriptObfuscatorCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
ArraySanitizer
)
.option(
'--domain-dest <string>',
'Allows the browser to be redirected to a passed domain if the source code isn\'t run on the domains specified by --domain-lock',
'--domain-lock-redirect-url <string>',
'Allows the browser to be redirected to a passed URL if the source code isn\'t run on the domains specified by --domain-lock',
)
.option(
'--exclude <list> (comma separated, without whitespaces)',
Expand Down
12 changes: 6 additions & 6 deletions src/custom-code-helpers/domain-lock/DomainLockCodeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper {
*/
protected override getCodeHelperTemplate (): string {
const domainsString: string = this.options.domainLock.join(';');
const domainsDest: string = this.options.domainDest;
const domainsLockRedirectUrl: string = this.options.domainLockRedirectUrl;
const [hiddenDomainsString, domainsStringDiff]: string[] = this.cryptUtils.hideString(
domainsString,
domainsString.length * 3
);
const [hiddenDomainDest, domainDestDiff]: string[] = this.cryptUtils.hideString(
domainsDest,
domainsDest.length * 3
const [hiddenDomainLockRedirectUrl, domainLockRedirectUrlDiff]: string[] = this.cryptUtils.hideString(
domainsLockRedirectUrl,
domainsLockRedirectUrl.length * 3
);
const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval
? this.getGlobalVariableTemplate()
Expand All @@ -107,8 +107,8 @@ export class DomainLockCodeHelper extends AbstractCustomCodeHelper {
domainLockFunctionName: this.domainLockFunctionName,
domainsStringDiff,
domains: hiddenDomainsString,
domainDestDiff,
domainDest: hiddenDomainDest,
domainLockRedirectUrlDiff: domainLockRedirectUrlDiff,
hiddenDomainLockRedirectUrl: hiddenDomainLockRedirectUrl,
globalVariableTemplate
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ export function DomainLockTemplate (): string {
}

if (!ok) {
const regExp2 = new RegExp("[{domainDestDiff}]", "g");
const domainDest = "{domainDest}".replace(regExp2, "");
const regExp2 = new RegExp("[{domainLockRedirectUrlDiff}]", "g");
const domainLockRedirectUrl = "{hiddenDomainLockRedirectUrl}".replace(regExp2, "");

that[document][location] = domainDest;
that[document][location] = domainLockRedirectUrl;
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/options/IOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface IOptions {
readonly debugProtectionInterval: boolean;
readonly disableConsoleOutput: boolean;
readonly domainLock: string[];
readonly domainDest: string;
readonly domainLockRedirectUrl: string;
readonly forceTransformStrings: string[];
readonly identifierNamesCache: TIdentifierNamesCache;
readonly identifierNamesGenerator: TTypeFromEnum<typeof IdentifierNamesGenerator>;
Expand Down
6 changes: 3 additions & 3 deletions src/options/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { HIGH_OBFUSCATION_PRESET } from './presets/HighObfuscation';

import { ValidationErrorsFormatter } from './ValidationErrorsFormatter';
import { IsAllowedForObfuscationTargets } from './validators/IsAllowedForObfuscationTargets';
import { IsDomainDestUrl } from './validators/IsDomainDestUrl';
import { IsDomainLockRedirectUrl } from './validators/IsDomainLockRedirectUrl';
import { IsIdentifierNamesCache } from './validators/IsIdentifierNamesCache';

@injectable()
Expand Down Expand Up @@ -138,8 +138,8 @@ export class Options implements IOptions {
/**
* @type {string}
*/
@IsDomainDestUrl()
public readonly domainDest!: string;
@IsDomainLockRedirectUrl()
public readonly domainLockRedirectUrl!: string;

/**
* @type {string[]}
Expand Down
4 changes: 2 additions & 2 deletions src/options/OptionsNormalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IOptionsNormalizer } from '../interfaces/options/IOptionsNormalizer';
import { ControlFlowFlatteningThresholdRule } from './normalizer-rules/ControlFlowFlatteningThresholdRule';
import { DeadCodeInjectionRule } from './normalizer-rules/DeadCodeInjectionRule';
import { DeadCodeInjectionThresholdRule } from './normalizer-rules/DeadCodeInjectionThresholdRule';
import { DomainDestRule } from './normalizer-rules/DomainDestRule';
import { DomainLockRedirectUrlRule } from './normalizer-rules/DomainLockRedirectUrlRule';
import { DomainLockRule } from './normalizer-rules/DomainLockRule';
import { IdentifierNamesCacheRule } from './normalizer-rules/IdentifierNamesCacheRule';
import { InputFileNameRule } from './normalizer-rules/InputFileNameRule';
Expand All @@ -30,7 +30,7 @@ export class OptionsNormalizer implements IOptionsNormalizer {
ControlFlowFlatteningThresholdRule,
DeadCodeInjectionRule,
DeadCodeInjectionThresholdRule,
DomainDestRule,
DomainLockRedirectUrlRule,
DomainLockRule,
IdentifierNamesCacheRule,
InputFileNameRule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { DEFAULT_PRESET } from '../presets/Default';
* @param {IOptions} options
* @returns {IOptions}
*/
export const DomainDestRule: TOptionsNormalizerRule = (options: IOptions): IOptions => {
export const DomainLockRedirectUrlRule: TOptionsNormalizerRule = (options: IOptions): IOptions => {
if (!options.domainLock.length) {
options = {
...options,
domainDest: <string>DEFAULT_PRESET.domainDest
domainLockRedirectUrl: <string>DEFAULT_PRESET.domainLockRedirectUrl
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/options/presets/Default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const DEFAULT_PRESET: TInputOptions = Object.freeze({
debugProtectionInterval: false,
disableConsoleOutput: false,
domainLock: [],
domainDest: 'about:blank',
domainLockRedirectUrl: 'about:blank',
exclude: [],
forceTransformStrings: [],
identifierNamesCache: null,
Expand Down
2 changes: 1 addition & 1 deletion src/options/presets/NoCustomNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const NO_ADDITIONAL_NODES_PRESET: TInputOptions = Object.freeze({
debugProtectionInterval: false,
disableConsoleOutput: false,
domainLock: [],
domainDest: 'about:blank',
domainLockRedirectUrl: 'about:blank',
exclude: [],
forceTransformStrings: [],
identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { IsAllowedForObfuscationTargets } from './IsAllowedForObfuscationTargets
/**
* @returns {PropertyDecorator}
*/
export const IsDomainDestUrl = (): PropertyDecorator => {
export const IsDomainLockRedirectUrl = (): PropertyDecorator => {
return (target: any, key: string | symbol): void => {
ValidateIf(({domainDest}: TInputOptions) => {
return domainDest !== DEFAULT_PRESET.domainDest;
ValidateIf(({domainLockRedirectUrl}: TInputOptions) => {
return domainLockRedirectUrl !== DEFAULT_PRESET.domainLockRedirectUrl;
})(target, key);
IsUrl({
require_protocol: false,
Expand Down
Loading