Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { NewsModule } from "./news/news.module";
import { EventsModule } from "./events/events.module";
import { ScrimsModule } from "./scrims/scrims.module";
import { LeaguesModule } from "./leagues/leagues.module";
import { CustomPagesModule } from "./custom-pages/custom-pages.module";
import { PluginsModule } from "./plugins/plugins.module";

@Module({
imports: [
Expand Down Expand Up @@ -153,7 +153,7 @@ import { CustomPagesModule } from "./custom-pages/custom-pages.module";
EventsModule,
ScrimsModule,
LeaguesModule,
CustomPagesModule,
PluginsModule,
],
providers: [loggerFactory()],
controllers: [AppController, QuickConnectController],
Expand Down
7 changes: 0 additions & 7 deletions src/custom-pages/custom-pages.module.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import { e_player_roles_enum } from "generated";
import { SystemService } from "src/system/system.service";

@Controller("custom-pages")
export class CustomPagesController {
// "custom-pages" is the pre-rename path. Deployed plugin ingresses hardcode it
// in their auth-url annotation, so dropping it would break them on upgrade.
@Controller(["plugins", "custom-pages"])
export class PluginsController {
@Get("authorize")
public authorize(@Req() request: Request, @Res() response: Response) {
// nginx forward-auth runs this for every request to a custom-page backend,
// nginx forward-auth runs this for every request to a plugin backend,
// including the CORS preflight. Preflight (OPTIONS) requests never carry
// cookies, so gating them would 401 the preflight and surface as a CORS
// error before the real credentialed request is sent. Let them through.
Expand All @@ -36,7 +38,15 @@
response.setHeader("X-5stack-Steam-Id", user.steam_id);
response.setHeader("X-5stack-Role", user.role);
response.setHeader("X-5stack-Name", encodeURIComponent(user.name ?? ""));
return response.status(200).end();

// nginx discards the body on an auth subrequest, so serving JSON here costs
// the forward-auth path nothing while letting a plugin backend validate a
// cookie server-side against this same endpoint.
return response.status(200).json({
steam_id: user.steam_id,
role: user.role,
name: user.name ?? "",
});
}

@Options("authorize")
Expand All @@ -60,7 +70,7 @@
return response.status(400).json({ error: "invalid url" });
}

if (CustomPagesController.isPrivateHost(raw)) {

Check failure on line 73 in src/plugins/plugins.controller.ts

View workflow job for this annotation

GitHub Actions / unit

Cannot find name 'CustomPagesController'.
return response.status(400).json({ error: "invalid url" });
}

Expand Down Expand Up @@ -106,7 +116,7 @@
scope: manifest.scope ?? null,
module: manifest.module ?? manifest.exposedModule ?? null,
requiredRole: manifest.requiredRole ?? null,
deployments: CustomPagesController.resolveDeployments(

Check failure on line 119 in src/plugins/plugins.controller.ts

View workflow job for this annotation

GitHub Actions / unit

Cannot find name 'CustomPagesController'.
manifest.deployments,
),
});
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/plugins.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from "@nestjs/common";
import { PluginsController } from "./plugins.controller";

@Module({
controllers: [PluginsController],
})
export class PluginsModule {}
6 changes: 3 additions & 3 deletions src/system/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class SystemService {
"hasura",
];

// Deployment names a custom page is never allowed to claim. A plugin manifest
// Deployment names a plugin is never allowed to claim. A plugin manifest
// is third-party input, so without this a plugin declaring `deployments:
// ["api"]` would render an Update button that restarts the panel itself.
private static RESERVED_DEPLOYMENTS = [
Expand Down Expand Up @@ -452,7 +452,7 @@ export class SystemService {
return services;
}

// Deployments declared by registered custom pages. The image is read off the
// Deployments declared by registered plugins. The image is read off the
// live deployment rather than the plugin manifest, so it can never drift from
// what is actually running -- the manifest only supplies the name.
private async getPluginServices() {
Expand Down Expand Up @@ -481,7 +481,7 @@ export class SystemService {
},
}));
} catch (error) {
this.logger.warn("unable to fetch custom pages", error);
this.logger.warn("unable to fetch plugins", error);
return services;
}

Expand Down
Loading