Skip to content

Commit 39ac615

Browse files
committed
set plain variables as env variables
1 parent 94243c9 commit 39ac615

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

apps/webapp/app/env.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ const EnvironmentSchema = z
108108

109109
PLAIN_API_KEY: z.string().optional(),
110110
PLAIN_CUSTOMER_CARDS_SECRET: z.string().optional(),
111+
PLAIN_CUSTOMER_CARDS_KEY: z.string().optional(),
112+
PLAIN_CUSTOMER_CARDS_HEADERS: z.string().optional(),
111113
WORKER_SCHEMA: z.string().default("graphile_worker"),
112114
WORKER_CONCURRENCY: z.coerce.number().int().default(10),
113115
WORKER_POLL_INTERVAL: z.coerce.number().int().default(1000),

apps/webapp/app/routes/api.v1.plain.customer-cards.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ const PlainCustomerCardRequestSchema = z.object({
3131
.optional(),
3232
});
3333

34-
// Sanitize headers to remove sensitive information before logging
35-
function sanitizeHeaders(request: Request, skipHeaders = ["authorization", "cookie"]): Partial<Record<string, string>> {
34+
function sanitizeHeaders(request: Request, skipHeaders?: string[]): Partial<Record<string, string>> {
35+
const authHeaderName = (env.PLAIN_CUSTOMER_CARDS_HEADERS || "Authorization").toLowerCase();
36+
const defaultSkipHeaders = skipHeaders || [authHeaderName, "cookie"];
3637
const sanitizedHeaders: Partial<Record<string, string>> = {};
3738

3839
for (const [key, value] of request.headers.entries()) {
39-
if (!skipHeaders.includes(key.toLowerCase())) {
40+
if (!defaultSkipHeaders.includes(key.toLowerCase())) {
4041
sanitizedHeaders[key] = value;
4142
}
4243
}
@@ -46,7 +47,8 @@ function sanitizeHeaders(request: Request, skipHeaders = ["authorization", "cook
4647

4748
// Authenticate the request from Plain
4849
function authenticatePlainRequest(request: Request): boolean {
49-
const authHeader = request.headers.get("Authorization");
50+
const authHeaderName = env.PLAIN_CUSTOMER_CARDS_HEADERS || "Authorization";
51+
const authHeader = request.headers.get(authHeaderName);
5052
const expectedSecret = env.PLAIN_CUSTOMER_CARDS_SECRET;
5153
if (!expectedSecret) {
5254
logger.warn("PLAIN_CUSTOMER_CARDS_SECRET not configured");
@@ -177,17 +179,18 @@ export async function action({ request }: ActionFunctionArgs) {
177179
// Build cards based on requested cardKeys
178180
const cards = [];
179181

182+
const accountDetailsKey = env.PLAIN_CUSTOMER_CARDS_KEY || "account-details";
180183
for (const cardKey of cardKeys) {
181184
switch (cardKey) {
182-
case "account-details": {
185+
case accountDetailsKey: {
183186
// Generate a signed one-time token for impersonation
184187
const impersonationToken = await generateImpersonationToken(user.id);
185188
// Build the impersonate URL with token for CSRF protection
186189
const impersonateUrl = `${env.APP_ORIGIN}/admin?impersonate=${user.id}&impersonationToken=${encodeURIComponent(impersonationToken)}`;
187190

188191
cards.push({
189-
key: "account-details",
190-
timeToLiveSeconds: 10,
192+
key: accountDetailsKey,
193+
timeToLiveSeconds: 15,
191194
components: [
192195
uiComponent.container({
193196
content: [

0 commit comments

Comments
 (0)