Skip to content

Commit

Permalink
fix(origin): allow any localhost origin
Browse files Browse the repository at this point in the history
This provides less protection, but not any different from the fact
that local programs can also access /vat or the websocket.

It's needed for Docker images to be independent of port or
listening address.
  • Loading branch information
michaelfig committed Oct 15, 2019
1 parent a704120 commit 80e35fc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
9 changes: 4 additions & 5 deletions lib/ag-solo/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,15 @@ export default async function start(basedir, withSES, argv) {
// Install the contracts, if given a client role.
if (argv.find(value => value.match(/^--role=.*client/)) !== undefined) {
const contractsDir = path.join(basedir, 'contracts');
const pairs = (await fs.promises.readdir(contractsDir)).reduce(
(prior, name) => {
const pairs = (await fs.promises.readdir(contractsDir))
.sort()
.reduce((prior, name) => {
const match = name.match(CONTRACT_REGEXP);
if (match) {
prior.push(`${match[1]}=${contractsDir}/${name}`);
}
return prior;
},
[],
);
}, []);

if (pairs.length > 0) {
// eslint-disable-next-line no-await-in-loop
Expand Down
14 changes: 10 additions & 4 deletions lib/ag-solo/vats/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import { getReplHandler } from './repl';
function build(E, D) {
let commandDevice;
let provisioner;
const homeObjects = { LOADING: 'fetching home objects' };
let exportedToCapTP = { LOADING: 'fetching home objects' };
const loaded = {};
loaded.p = new Promise((resolve, reject) => {
loaded.res = resolve;
loaded.rej = reject;
});
harden(loaded);
const homeObjects = { LOADING: loaded.p };
let exportedToCapTP = { LOADING: loaded.p };

let handler = {};
let canvasState;
Expand Down Expand Up @@ -90,9 +96,9 @@ function build(E, D) {
},

setPresences(ps, privateObjects) {
delete homeObjects.LOADING;
exportedToCapTP = Object.assign({}, ps, privateObjects);
exportedToCapTP = { ...ps, ...privateObjects };
Object.assign(homeObjects, ps, privateObjects);
loaded.res('chain bundle loaded');
if (ps.canvasStatePublisher) {
const subscriber = harden({
notify(m) {
Expand Down
16 changes: 4 additions & 12 deletions lib/ag-solo/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,16 @@ export function makeHTTPListener(basedir, port, host, inboundCommand) {
const url = new URL(origin);
const isLocalhost = hostname =>
hostname.match(/^(localhost|127\.0\.0\.1)$/);
if (isLocalhost(host)) {
if (!isLocalhost(url.hostname)) {
console.log(id, `Invalid origin host ${origin} is not local`);
return false;
}
} else if (url.hostname !== host) {
console.log(id, `Invalid origin host ${origin}`);

if (!isLocalhost(url.hostname)) {
console.log(id, `Invalid origin host ${origin} is not localhost`);
return false;
}

if (url.protocol !== 'http:' && url.protocol !== 'https:') {
console.log(id, `Invalid origin protocol ${origin}`, url.protocol);
return false;
}
if (String(url.port) !== String(port)) {
console.log(id, `Invalid origin port ${origin}`, url.port);
return false;
}

return true;
};

Expand Down
2 changes: 1 addition & 1 deletion provisioning-server/src/ag_pserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def ret(server_message):
resp = yield treq.post(controller_url, m.encode('utf-8'), reactor=reactor,
headers={
b'Content-Type': [b'application/json'],
b'Origin': [controller_url.encode('utf-8')],
b'Origin': [b'http://127.0.0.1'],
})
if resp.code < 200 or resp.code >= 300:
raise Exception('invalid response code ' + str(resp.code))
Expand Down

0 comments on commit 80e35fc

Please sign in to comment.