Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Using xhook to intercept XHR request #1

Open
FWeinb opened this issue Feb 7, 2018 · 1 comment
Open

Using xhook to intercept XHR request #1

FWeinb opened this issue Feb 7, 2018 · 1 comment

Comments

@FWeinb
Copy link

FWeinb commented Feb 7, 2018

Thanks for building this extension! I am using rclonejs for something similar (amazon drive) using xhook.

const nameKey = new Uint8Array("Decrypted Key")
const nameTweak = new Uint8Array("Decrypted Tweak");
const cipher = PathCipher({nameKey, nameTweak});
const tryDecrypt = (name) => {
    try {
        name = cipher.decrypt(name);
    } catch (e) {
    }
    return name;
}
const sortAlphaDesc = (a,b) => {
    if (a.name < b.name)
        return -1;
    if (a.name > b.name)
        return 1;
    return 0;
}

const sortAlphaAsc = (b, a) => {
    if (a.name < b.name)
        return -1;
    if (a.name > b.name)
        return 1;
    return 0;
}

xhook.before((request) => {
    if (request.url.indexOf('/drive/v1/nodes') !== -1 && request.url.indexOf('filters') !== -1 ){
        console.log(request);
    }
});

xhook.after(function(request, response) {
    if (request.url.indexOf('/drive/v1/nodes') !== -1){
        const sortASC = request.url.indexOf("name+ASC") !== -1;
        const sortDESC = request.url.indexOf("name+DESC") !== -1;
        const req = JSON.parse(response.text);
        if (req.name) {
            req.name = tryDecrypt(req.name);
        }
        if (req.data) {
            req.data = req.data.filter(Boolean).map((item) => {
                item.name = tryDecrypt(item.name);
                return item;
            });
            if (sortASC) {
                req.data.sort(sortAlphaAsc);
            }
            if (sortDESC) {
                req.data.sort(sortAlphaDesc);
            }
        }
        response.text = JSON.stringify(req);
    }
});

I didn't look into Google Drive yet and don't know if a similar approach would be feasible.

@sscotth
Copy link
Owner

sscotth commented Feb 7, 2018

Yea, I was thinking about that for a future version. When I browse on gdrive it makes a GETs to https://clients6.google.com/drive/v2internal/files with a response like this:

{
	"kind": "drive#fileList",
	"...": "...",
	"items": [{
			"...": "...",
			"title": "** ENCRYPTED FILE NAME **",
			"...": "..."
		},
		{
			"...": "...",
			"title": "** ENCRYPTED FILE NAME **",
			"...": "..."
		}
	]
}

This has the possibility of being intercepted and manipulated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants