Skip to content

Commit

Permalink
hotfix: change protected fields to allow scoped fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ceelsoin committed May 4, 2023
1 parent 984d7fd commit 675935d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions lib/http/SchemaResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ class SchemaResponse {
this.functionsRequest = functionsRequest;
this.res = res;
this.schemaName = schemaName;
this.protectedFields = config.responseProtectedFields;
this.allowedFields = config.responseAllowedFields;
}

removeProtectedFields(data) {
for (const field of this.protectedFields) {
delete data[field];
};
};
removeNotAllowedFields(data) {
const fieldsToRemove = Object.keys(data.env.filter(field => !this.allowedFields.includes(field)));
for (const field of fieldsToRemove) {
delete data.env[field];
}
}

json(data) {
this.removeProtectedFields(data);
this.removeNotAllowedFields(data);
const schemeAndAuthority = this.functionsRequest.schemeAndAuthority();
this.res.set('Content-Type', `application/json; charset=utf-8; profile=${schemeAndAuthority}/_schemas/${this.schemaName}`);
this.res.end(JSON.stringify(data));
Expand Down
2 changes: 1 addition & 1 deletion lib/support/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
defaultGlobalModules: ConfigDiscovery.getList('DEFAULT_GLOBAL_MODULES', DEFAULT_GLOBAL_MODULES),
bodyParserLimit: process.env.BODY_PARSER_LIMIT || '1mb',
redisConnectionTimeout: ConfigDiscovery.getInt('REDIS_CONNECTION_TIMEOUT', 2000),
responseProtectedFields: ConfigDiscovery.getList('RESPONSE_PROTECTED_FIELDS', ['env']),
responseAllowedFields: ConfigDiscovery.getList('RESPONSE_ALLOWED_FIELDS', ['BACKSTAGE_CLIENT_ID']),
metric: {
client: process.env.METRIC_CLIENT,
udpHost: process.env.METRIC_UDP_HOST,
Expand Down

0 comments on commit 675935d

Please sign in to comment.