Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Fixes naming convention permission check for data items with path attribute only. #830

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions lib/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ class Poller {
allowed, reason
}
}
}
if (!reNaming.test(secretProperty.key)) {
} else if (!reNaming.test(secretProperty.key)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking its better we check for the respective keys and validate them if present.

      externalData.forEach((secretProperty, index) => {
        if ('path' in secretProperty && !reNaming.test(secretProperty.path)) {
          allowed = false
          reason = `path ${secretProperty.path} does not match naming convention ${namingConvention}`
          return {
            allowed, reason
          }
        }

        if ('key' in secretProperty && !reNaming.test(secretProperty.key)) {
          allowed = false
          reason = `key name ${secretProperty.key} does not match naming convention ${namingConvention}`
          return {
            allowed, reason
          }
        }
      })

They never should be present at the same time, but if validation or other layer of the code allows for it, then this would potentially allow bypassing the validation. By supplying a bogus path that would validate and using a key which is ignored by validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, checking path and key independently makes sense. I updated the code to do that.

allowed = false
reason = `key name ${secretProperty.key} does not match naming convention ${namingConvention}`
return {
Expand Down
10 changes: 10 additions & 0 deletions lib/poller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,16 @@ describe('Poller', () => {
},
permitted: false
},
{
// test regex on path
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
descriptor: {
data: [
{ path: 'dev/team-a/secret' }
]
},
permitted: true
},
vladlosev marked this conversation as resolved.
Show resolved Hide resolved
{
// test regex on path
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
Expand Down