Skip to content

Commit

Permalink
Merge pull request #1035 from matrix-org/hs/auth-provisioner
Browse files Browse the repository at this point in the history
Authenticate requests to the /provision endpoint
  • Loading branch information
Half-Shot committed Apr 16, 2020
2 parents d24fff6 + 862c1c3 commit c2bbfd2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 56 deletions.
1 change: 1 addition & 0 deletions changelog.d/1035.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**SECURITY FIX** The bridge now authenticatess the /_matrix/provision set of endpoints. It now requires either a `access_token` query parameter or a `Authorization` header containing the `hs_token` provided in the registration file.
93 changes: 40 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"js-yaml": "^3.2.7",
"logform": "^2.1.2",
"matrix-appservice": "^0.4.1",
"matrix-appservice-bridge": "^1.11.1",
"matrix-appservice-bridge": "^1.12.1",
"matrix-lastactive": "^0.1.3",
"nedb": "^1.1.2",
"nopt": "^3.0.1",
Expand Down
9 changes: 8 additions & 1 deletion src/provisioning/Provisioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,20 @@ export class Provisioner {
});
}

// Deal with CORS (temporarily for s-web)
app.use((req, res, next) => {
// Deal with CORS (temporarily for s-web)
if (this.isProvisionRequest(req)) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept");
}
if (!this.ircBridge.getAppServiceBridge().requestCheckToken(req)) {
res.status(403).send({
errcode: "M_FORBIDDEN",
error: "Bad token supplied"
});
return;
}
next();
});

Expand Down
2 changes: 1 addition & 1 deletion types/matrix-appservice-bridge/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ declare module 'matrix-appservice-bridge' {
getPrometheusMetrics(): PrometheusMetrics;
getIntent(userId?: string): Intent;
getIntentFromLocalpart(localpart: string): Intent;

requestCheckToken(req: Express.Request): boolean;
run(port: number, config: undefined, appservice?: import("matrix-appservice").AppService, hostname?: string): void;
registerBridgeGauges(cb: () => void): void;
getClientFactory(): ClientFactory;
Expand Down

0 comments on commit c2bbfd2

Please sign in to comment.