Skip to content

Commit

Permalink
Restrict replay attacks with timestamp for outline
Browse files Browse the repository at this point in the history
  • Loading branch information
tectonick committed Dec 29, 2024
1 parent b54ba20 commit 7812c97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ HASSTOKEN - Home Assistant API token
HACKERGOOGLEAPIKEY - Google Calendar API token
OPENAIAPIKEY - OpenAI API token
SONAR_TOKEN - Sonar Cloud analysis token
WIKIAPIKEY - Outline Wiki API token
WIKIAPIKEY - Outline Wiki API token
OUTLINE_SIGNING_SECRET - Outline API signing secret for webhooks

You can use a .env file in the root folder for development. Check the .env.example file for reference.
Expand Down
9 changes: 9 additions & 0 deletions utils/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Logger } from "winston";

import { decrypt } from "./security";
import { safeJsonStringify } from "./text";
import { MINUTE } from "./date";

// Optional type for a legacy hass module
type RequestWithOptionalTokenBody = Request<ParamsDictionary, any, Optional<{ token?: string }>, ParsedQs, Record<string, any>>;
Expand Down Expand Up @@ -89,6 +90,14 @@ export function createOutlineVerificationMiddleware(logger: Logger, token?: stri
}

const [timestamp, signature] = header.split(",").map(part => part.split("=")[1]);
const parsedTimestamp = Number(timestamp);

if (isNaN(parsedTimestamp) || parsedTimestamp < Date.now() - MINUTE) {
logger.error(`Got request with outdated outline signature from ${req.ip}`);
res.status(401).send({ message: "Request is outdated" });
return;
}

const bodyString = safeJsonStringify(req.body);

if (!bodyString) {
Expand Down

0 comments on commit 7812c97

Please sign in to comment.