Skip to content

Commit

Permalink
T
Browse files Browse the repository at this point in the history
t
t
t
t
t
t
t
  • Loading branch information
caracal-js committed Jul 26, 2021
1 parent ccfee43 commit e912cf4
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ssl = {
const server = https.createServer(ssl);
const Corrosion = require('../');
const proxy = new Corrosion({
codec: 'xor',
codec: 'base64',
});

server.on('request', (request, response) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function createDocumentRewriter(ctx) {
}),
set: domain.set,
});
Object.defineProperty(ctx.window.Document.prototype, 'title', {
if (ctx.config.title) Object.defineProperty(ctx.window.Document.prototype, 'title', {
get: new Proxy(title.get, {
apply: () => spoofTitle,
}),
Expand Down
8 changes: 7 additions & 1 deletion lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Corrosion extends require('../rewrite') {
get windowTop() {
if (this.serviceWorker) return false;
try {
return this.window.parent.$corrosion ? this.window.parent : this.window;
return this.window.top.$corrosion ? this.window.top : this.window;
} catch(e) {
return this.window;
};
Expand Down Expand Up @@ -107,6 +107,8 @@ class Corrosion extends require('../rewrite') {
if (obj == this.window || obj == this.document) {
if (key == 'location') obj = this;
};
if (obj == this.window.parent) obj = this.windowParent;
if (obj == this.window.top) obj = this.windowTop;

switch(operator) {
case '+=':
Expand Down Expand Up @@ -150,10 +152,14 @@ class Corrosion extends require('../rewrite') {
};
setIdentifier(identifier, val) {
if (identifier == this.window.location) return this.location.href = val;
if (identifier == this.window.parent) return this.windowParent = val;
if (identifier == this.window.top) return this.windowTop = val;
return identifier = val;
};
getIdentifier(identifier) {
if (identifier == this.window.location) return this.location;
if (identifier == this.window.parent) return this.windowParent;
if (identifier == this.window.top) return this.windowTop;
return identifier;
};
updateLocation() {
Expand Down
6 changes: 3 additions & 3 deletions lib/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HTMLRewriter {
if (node.textContent) node.textContent = this.ctx.css.process(node.textContent, meta);
break;
case 'TITLE':
if (node.textContent) node.textContent = 'Service';
if (node.textContent && this.ctx.config.title) node.textContent = this.ctx.config.title;
break;
case 'SCRIPT':
if (node.getAttribute('type') != 'application/json' && node.textContent) node.textContent = this.ctx.js.process(node.textContent);
Expand Down Expand Up @@ -112,7 +112,7 @@ class HTMLRewriter {
childNodes: [
{
nodeName: '#text',
value: this.ctx.config.title,
value: this.ctx.config.title || '',
}
],
attrs: [],
Expand All @@ -134,7 +134,7 @@ class HTMLRewriter {
childNodes: [
{
nodeName: '#text',
value: `window.$corrosion = new Corrosion({ window, codec: '${this.ctx.config.codec || 'plain'}', prefix: '${this.ctx.prefix}', ws: ${this.ctx.config.ws}, cookie: ${this.ctx.config.cookie}, title: '${this.ctx.config.title}', }); $corrosion.init(); document.currentScript.remove();`
value: `window.$corrosion = new Corrosion({ window, codec: '${this.ctx.config.codec || 'plain'}', prefix: '${this.ctx.prefix}', ws: ${this.ctx.config.ws}, cookie: ${this.ctx.config.cookie}, title: ${typeof this.ctx.config.title == 'boolean' ? this.ctx.config.title : '\'' + this.ctx.config.title + '\''}, }); $corrosion.init(); document.currentScript.remove();`
},
],
attrs: [],
Expand Down
8 changes: 4 additions & 4 deletions lib/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class JSRewriter {
compact: true,
},
};
this.rewrite = ['location'];
this.rewrite = ['location', 'parent', 'top'];
this.map = [
{
type: 'MemberExpression',
Expand Down Expand Up @@ -73,7 +73,7 @@ class JSRewriter {
if (parent.type == 'ExportSpecifier') return;
if (parent.type == 'ImportSpecifier') return;
if (parent.type == 'FunctionDeclaration' && parent.params.includes(node)) return;
if (node.name != 'location') return;
if (!this.rewrite.includes(node.name)) return;
if (node.preventRewrite) return;
let identifier = '$corrosionGetIdentifier';
let nodeToRewrite = node;
Expand All @@ -95,13 +95,13 @@ class JSRewriter {
switch(node.property.type) {
case 'Identifier':
//if (node.computed) rewrite = true;
if (!node.computed && node.property.name == 'location') {
if (!node.computed && this.rewrite.includes(node.property.name)) {
node.property = this.createLiteral(node.property.name);
rewrite = true;
};
break;
case 'Literal':
if (node.property.value == 'location') rewrite = true;
if (this.rewrite.includes(node.property.name)) rewrite = true;
break;
case 'TemplateLiteral':
rewrite = true;
Expand Down
7 changes: 0 additions & 7 deletions lib/server/ads.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const createRequestProxy = require('./request');
const createGateway = require('./gateway');
const middleware = {
...require('./headers'),
reconnectUrl: require('./reconnect-url'),
decompress: require('./decompress'),
rewriteBody: require('./rewrite-body'),
};
Expand All @@ -27,7 +26,6 @@ class Corrosion extends require('../rewrite') {
if (this.config.standardMiddleware) {
this.config.requestMiddleware.unshift(
middleware.requestHeaders,
middleware.reconnectUrl
);
this.config.responseMiddleware.unshift(
middleware.responseHeaders,
Expand Down
5 changes: 0 additions & 5 deletions lib/server/reconnect-url.js

This file was deleted.

0 comments on commit e912cf4

Please sign in to comment.