mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
fix(api): 🐛 Automatically rewrite http to https in federation
This commit is contained in:
parent
c28628ebb3
commit
673b7d0bae
3
index.ts
3
index.ts
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue