Skip to content

Commit

Permalink
[HTTP] Only allow setting server.restrictInternalApis on serverless (
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jul 25, 2023
1 parent 0f7129d commit 492cfdf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -509,6 +509,27 @@ describe('versioned', () => {
});
});

describe('restrictInternalApis', () => {
it('is only allowed on serverless', () => {
expect(() => config.schema.validate({ restrictInternalApis: false }, {})).toThrow(
/a value wasn't expected/
);
expect(() => config.schema.validate({ restrictInternalApis: true }, {})).toThrow(
/a value wasn't expected/
);
expect(
config.schema.validate({ restrictInternalApis: true }, { serverless: true })
).toMatchObject({
restrictInternalApis: true,
});
});
it('defaults to false', () => {
expect(
config.schema.validate({ restrictInternalApis: undefined }, { serverless: true })
).toMatchObject({ restrictInternalApis: false });
});
});

describe('HttpConfig', () => {
it('converts customResponseHeaders to strings or arrays of strings', () => {
const httpSchema = config.schema;
Expand All @@ -535,4 +556,11 @@ describe('HttpConfig', () => {
nested: '{"foo":1,"bar":"dolly"}',
});
});

it('defaults restrictInternalApis to false', () => {
const rawConfig = config.schema.validate({}, {});
const rawCspConfig = cspConfig.schema.validate({});
const httpConfig = new HttpConfig(rawConfig, rawCspConfig, ExternalUrlConfig.DEFAULT);
expect(httpConfig.restrictInternalApis).toBe(false);
});
});
12 changes: 10 additions & 2 deletions packages/core/http/core-http-server-internal/src/http_config.ts
Expand Up @@ -167,7 +167,14 @@ const configSchema = schema.object(
},
}
),
restrictInternalApis: schema.boolean({ defaultValue: false }), // allow access to internal routes by default to prevent breaking changes in current offerings
// allow access to internal routes by default to prevent breaking changes in current offerings
restrictInternalApis: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({ defaultValue: false }),
schema.never()
),

versioned: schema.object({
/**
* Which handler resolution algo to use: "newest" or "oldest".
Expand Down Expand Up @@ -316,7 +323,8 @@ export class HttpConfig implements IHttpConfig {
this.requestId = rawHttpConfig.requestId;
this.shutdownTimeout = rawHttpConfig.shutdownTimeout;

this.restrictInternalApis = rawHttpConfig.restrictInternalApis;
// default to `false` to prevent breaking changes in current offerings
this.restrictInternalApis = rawHttpConfig.restrictInternalApis ?? false;
this.eluMonitor = rawHttpConfig.eluMonitor;
this.versioned = rawHttpConfig.versioned;
}
Expand Down

0 comments on commit 492cfdf

Please sign in to comment.