Skip to content

Commit

Permalink
Prevent errors when non-string CSP values are defined in the manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Feb 12, 2024
1 parent 1cdb761 commit 6c9dad6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parsers/manifestjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,10 @@ export default class ManifestJSONParser extends JSONParser {
}

validateCspPolicyString(policy, manifestPropName) {
if (typeof policy !== 'string') {
return;
}

const directives = parseCspPolicy(policy);

// The order is important here, 'default-src' needs to be before
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/parsers/test.manifestjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,24 @@ describe('ManifestJSONParser', () => {
expect(warningsV3.length).toEqual(6);
}
);

// See: https://github.com/mozilla/addons-linter/issues/5194
it('should handle non-string values', () => {
const addonLinter = new Linter({ _: ['bar'] });
const json = validManifestJSON({ content_security_policy: [true] });

const manifestJSONParser = new ManifestJSONParser(
json,
addonLinter.collector
);

const { errors } = addonLinter.collector;
expect(errors[0]).toMatchObject({
code: messages.MANIFEST_FIELD_INVALID.code,
message: '"/content_security_policy" must be string',
});
expect(manifestJSONParser.isValid).toEqual(false);
});
});

describe('update_url', () => {
Expand Down

0 comments on commit 6c9dad6

Please sign in to comment.