mirror of
https://github.com/outline/outline.git
synced 2026-12-05 02:44:34 +03:00
fix: Add yet another guard against crawlers consuming magic links (#10457)
This commit is contained in:
1 parent
633d41e67f
commit
76691e8aaa
3 files changed
+16
-7
No files matched your search
+10
-2
@@ -6,7 +6,7 @@ import "./logging/tracer"; // must come before importing any instrumented module
|
||||
|
||||
import http from "http";
|
||||
import https from "https";
|
||||
import Koa from "koa";
|
||||
import Koa, { Context } from "koa";
|
||||
import helmet from "koa-helmet";
|
||||
import logger from "koa-logger";
|
||||
import Router from "koa-router";
|
||||
@@ -90,6 +90,7 @@ async function start(_id: number, disconnect: () => void) {
|
||||
|
||||
/** Perform a redirect on the browser so that the user's auth cookies are included in the request. */
|
||||
app.context.redirectOnClient = function (
|
||||
this: Context,
|
||||
/** The URL to redirect to */
|
||||
url: string,
|
||||
/**
|
||||
@@ -113,6 +114,13 @@ async function start(_id: number, disconnect: () => void) {
|
||||
)}" value="${escape(value)}" />`;
|
||||
});
|
||||
|
||||
if (this.userAgent.isBot) {
|
||||
formFields += `
|
||||
<p>If you are not redirected automatically, please click the button below.</p>
|
||||
<input type="submit" value="Continue" />
|
||||
`;
|
||||
}
|
||||
|
||||
this.body = `
|
||||
<html>
|
||||
<head>
|
||||
@@ -123,7 +131,7 @@ async function start(_id: number, disconnect: () => void) {
|
||||
${formFields}
|
||||
</form>
|
||||
<script nonce="${this.state.cspNonce}">
|
||||
document.getElementById('redirect-form').submit();
|
||||
${!this.userAgent.isBot} && document.getElementById('redirect-form').submit();
|
||||
</script>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import crypto from "crypto";
|
||||
import path from "path";
|
||||
import { formatRFC7231 } from "date-fns";
|
||||
import Koa, { BaseContext } from "koa";
|
||||
import Koa from "koa";
|
||||
import Router from "koa-router";
|
||||
import send from "koa-send";
|
||||
import userAgent, { UserAgentContext } from "koa-useragent";
|
||||
import { languages } from "@shared/i18n";
|
||||
import { IntegrationType, TeamPreference } from "@shared/types";
|
||||
import { parseDomain } from "@shared/utils/domains";
|
||||
@@ -24,8 +23,6 @@ import errors from "./errors";
|
||||
const koa = new Koa();
|
||||
const router = new Router();
|
||||
|
||||
koa.use<BaseContext, UserAgentContext>(userAgent);
|
||||
|
||||
// serve public assets
|
||||
router.use(["/images/*", "/email/*", "/fonts/*"], async (ctx, next) => {
|
||||
let done;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* oxlint-disable @typescript-eslint/no-var-requires */
|
||||
import { Server } from "https";
|
||||
import Koa from "koa";
|
||||
import Koa, { BaseContext } from "koa";
|
||||
import compress from "koa-compress";
|
||||
import { dnsPrefetchControl, referrerPolicy } from "koa-helmet";
|
||||
import mount from "koa-mount";
|
||||
@@ -20,6 +20,7 @@ import routes from "../routes";
|
||||
import api from "../routes/api";
|
||||
import auth from "../routes/auth";
|
||||
import oauth from "../routes/oauth";
|
||||
import userAgent, { UserAgentContext } from "koa-useragent";
|
||||
|
||||
export default function init(app: Koa = new Koa(), server?: Server) {
|
||||
void initI18n();
|
||||
@@ -45,6 +46,9 @@ export default function init(app: Koa = new Koa(), server?: Server) {
|
||||
app.proxy = true;
|
||||
}
|
||||
|
||||
// Make `ctx.userAgent` available
|
||||
app.use<BaseContext, UserAgentContext>(userAgent);
|
||||
|
||||
app.use(compress());
|
||||
|
||||
// Monitor server connections
|
||||
|
||||
Reference in new issue
Block a user