Skip to content

Commit 0a85072

Browse files
committed
Add frame-ancestors to content security policy directives
1 parent 87f6129 commit 0a85072

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/rules/content-security-policy.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ describe("convertFetchDirectiveToString", () => {
254254
});
255255
});
256256

257+
context.only('when giving an object which has "frameAncestors" property', () => {
258+
it('should return value which includes "frame-ancestors"', () => {
259+
expect(convertFetchDirectiveToString({ frameAncestors: "'self'" })).toBe("frame-ancestors 'self'");
260+
expect(convertFetchDirectiveToString({ frameAncestors: ["'self'", "https://www.example.com/"] })).toBe(
261+
"frame-ancestors 'self' https://www.example.com/",
262+
);
263+
264+
expect(convertFetchDirectiveToString({ "frame-ancestors": "'self'" })).toBe("frame-ancestors 'self'");
265+
expect(convertFetchDirectiveToString({ "frame-ancestors": ["'self'", "https://www.example.com/"] })).toBe(
266+
"frame-ancestors 'self' https://www.example.com/",
267+
);
268+
});
269+
});
270+
257271
context('when giving an object which has "imgSrc" property', () => {
258272
it('should return value which includes "img-src"', () => {
259273
expect(convertFetchDirectiveToString({ imgSrc: "'self'" })).toBe("img-src 'self'");

src/rules/content-security-policy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type FetchDirective = {
2828
"default-src": DirectiveSource;
2929
fontSrc: DirectiveSource;
3030
"font-src": DirectiveSource;
31+
frameAncestors: DirectiveSource;
32+
"frame-ancestors": DirectiveSource;
3133
frameSrc: DirectiveSource;
3234
"frame-src": DirectiveSource;
3335
imgSrc: DirectiveSource;
@@ -98,6 +100,8 @@ const fetchDirectiveNamesByKey: Record<keyof FetchDirective, string> = {
98100
"default-src": "default-src",
99101
fontSrc: "font-src",
100102
"font-src": "font-src",
103+
frameAncestors: "frame-ancestors",
104+
"frame-ancestors": "frame-ancestors",
101105
frameSrc: "frame-src",
102106
"frame-src": "frame-src",
103107
imgSrc: "img-src",

0 commit comments

Comments
 (0)