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

Hide sensitive keys in appservice query parameters #241

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/appservice/Appservice.ts
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