Skip to content

Commit

Permalink
Added script bundling every start up + better document.domain rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
caracal-js committed Jul 28, 2021
1 parent 21d403e commit 9e63275
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const proxy = new Corrosion({
codec: 'xor',
});

proxy.bundleScripts();

server.on('request', (request, response) => {
if (request.url.startsWith(proxy.prefix)) return proxy.request(request, response);
response.end(fs.readFileSync(__dirname + '/index.html', 'utf-8'));
Expand Down
11 changes: 9 additions & 2 deletions lib/browser/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function createDocumentRewriter(ctx) {
const baseURI = Object.getOwnPropertyDescriptor(ctx.window.Node.prototype, 'baseURI');
const cookieEnabled = Object.getOwnPropertyDescriptor(ctx.window.Navigator.prototype, 'cookieEnabled');
let spoofTitle = '';
let spoofDomain = ctx.location.hostname;

if (ctx.window.Document.prototype.write) {
ctx.window.Document.prototype.write = new Proxy(ctx.window.Document.prototype.write, {
Expand Down Expand Up @@ -149,9 +150,15 @@ function createDocumentRewriter(ctx) {
});
Object.defineProperty(ctx.window.Document.prototype, 'domain', {
get: new Proxy(domain.get, {
apply: () => ctx.location.hostname,
apply: () => spoofDomain,
}),
set: new Proxy(domain.set, {
apply: (target, that, [ val ]) => {
console.log(val, ctx.location.hostname)
if (!val.toString().endsWith(ctx.location.hostname.split('.').slice(-2).join('.'))) return Reflect.apply(target, that, ['']);
return spoofDomain = val;
},
}),
set: domain.set,
});
if (ctx.config.title) Object.defineProperty(ctx.window.Document.prototype, 'title', {
get: new Proxy(title.get, {
Expand Down

0 comments on commit 9e63275

Please sign in to comment.