Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate requests to the /provision endpoint #1035

Merged
merged 3 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion src/provisioning/Provisioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,18 @@ export class Provisioner {

// Deal with CORS (temporarily for s-web)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment which once described the entire purpose of this handler has now become outdated.

app.use((req, res, next) => {
if (!this.ircBridge.getAppServiceBridge().requestCheckToken(req)) {
return res.status(403).send({
errcode: "M_FORBIDDEN",
error: "Bad token supplied,"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error: "Bad token supplied,"
error: "Bad token supplied"

});
}
if (this.isProvisionRequest(req)) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept");
}
next();
return next();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does returning next() do? I've never seen that as a pattern.

});

app.post("/_matrix/provision/link",
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