The PR #373 added support for complex resources when a wildcard is present. However it fails when the Resource is just a '*'.
// ./src/authMatchPolicyResource.js
module.exports = (policyResource, resource) => {
if (policyResource === resource) {
return true;
}
else if (policyResource.includes('*')) {
//Policy contains a wildcard resource
const splitPolicyResource = policyResource.split(':');
const splitResource = resource.split(':');
//These variables contain api id, stage, method and the path
//for the requested resource and the resource defined in the policy
const splitPolicyResourceApi = splitPolicyResource[5].split('/'); // this line fails
const splitResourceApi = splitResource[5].split('/');
return splitPolicyResourceApi.every((resourceFragment, index) => {
if (splitResourceApi.length >= index + 1) {
return (splitResourceApi[index] === resourceFragment || resourceFragment === '*');
}
//The last position in the policy resource is a '*' it matches all
//following resource fragments
return splitPolicyResourceApi[splitPolicyResourceApi.length - 1] === '*';
});
}
return false;
};
I think it fails in line 11 because it tries to split the index [5] of an already splitted string which is not even an array. So it fails with TypeError: Uncaught error: Cannot read property 'split' of undefined
Maybe I'm doing something wrong, but in the case it is indeed a bug: Is there a fix for this already in place or should I make a PR for this?
I think an if statement should do the trick, but I'm open to better patterns
Added a quick fix https://github.com/dherault/serverless-offline/pull/391
I'm also having the same issue. The if statement would fix the problem however I have altered my policy to arn:aws:execute-api:*:*:*/*/* in the meantime.
Most helpful comment
I think an if statement should do the trick, but I'm open to better patterns