fix(api): 🐛 Automatically rewrite http to https in federation

This commit is contained in:
Jesse Wierzbinski 2024-05-17 11:42:42 -10:00
parent c28628ebb3
commit 673b7d0bae
No known key found for this signature in database
3 changed files with 16 additions and 2 deletions

View file

@ -118,7 +118,8 @@ app.use(agentBans);
app.use(bait);
app.use(logger);
app.use(boundaryCheck);
app.use(urlCheck);
// Disabled as federation now checks for this
// app.use(urlCheck);
// Inject own filesystem router
for (const [route, path] of Object.entries(routes)) {

View file

@ -435,11 +435,13 @@ export const configValidator = z.object({
enabled: z.boolean().default(false),
software: z.enum(["lysand-ap"]).or(z.string()),
allowed_ips: z.array(z.string().trim()).default([]),
token: z.string().default(""),
})
.default({
enabled: false,
software: "lysand-ap",
allowed_ips: [],
token: "",
}),
})
.default({
@ -460,6 +462,7 @@ export const configValidator = z.object({
enabled: false,
software: "lysand-ap",
allowed_ips: [],
token: "",
},
}),
instance: z

View file

@ -110,12 +110,22 @@ export default (app: Hono) =>
sender.getUser().publicKey,
);
// If base_url uses https and request uses http, rewrite request to use https
// This fixes reverse proxy errors
const reqUrl = new URL(context.req.url);
if (
new URL(config.http.base_url).protocol === "https:" &&
reqUrl.protocol === "http:"
) {
reqUrl.protocol = "https:";
}
const isValid = await validator
.validate(
signature,
new Date(Date.parse(date)),
context.req.method as HttpVerb,
new URL(context.req.url),
reqUrl,
await context.req.text(),
)
.catch((e) => {