Skip to content

Commit

Permalink
Hide sensitive keys in appservice query parameters (#241)
Browse files Browse the repository at this point in the history
* Hide sensitive keys in appservice query parameters

* Update src/appservice/Appservice.ts
  • Loading branch information
Half-Shot authored Jul 6, 2022
1 parent 0f4778a commit 76d63b9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/appservice/Appservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as express from "express";
import { EventEmitter } from "events";
import * as morgan from "morgan";
import * as LRU from "lru-cache";
import { stringify } from "querystring";

import { Intent } from "./Intent";
import {
Expand All @@ -17,6 +18,7 @@ import {
MemoryStorageProvider,
Metrics,
OTKAlgorithm,
redactObjectForLogging,
} from "..";
import { MatrixBridge } from "./MatrixBridge";
import { IApplicationServiceProtocol } from "./http_responses";
Expand Down Expand Up @@ -263,7 +265,14 @@ export class Appservice extends EventEmitter {
this.cryptoStorage = options.cryptoStorage;

this.app.use(express.json({ limit: Number.MAX_SAFE_INTEGER })); // disable limits, use a reverse proxy
this.app.use(morgan("combined", {
morgan.token('url-safe', (req: express.Request) =>
`${req.path}?${stringify(redactObjectForLogging(req.query ?? {}))}`,
);

this.app.use(morgan({
// Same as "combined", but with sensitive values removed from requests.
format: ':remote-addr - :remote-user [:date[clf]] ":method :url-safe HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"',
}, {
stream: { write: LogService.info.bind(LogService, 'Appservice') },
}));

Expand Down

0 comments on commit 76d63b9

Please sign in to comment.