Skip to content

Commit ed9be74

Browse files
committed
Add Content Security Policy
1 parent 28298bd commit ed9be74

File tree

5 files changed

+232
-6
lines changed

5 files changed

+232
-6
lines changed

baselines/dom.generated.d.ts

+85-5
Original file line numberDiff line numberDiff line change
@@ -1693,14 +1693,16 @@ interface ScrollToOptions extends ScrollOptions {
16931693
interface SecurityPolicyViolationEventInit extends EventInit {
16941694
blockedURI?: string;
16951695
columnNumber?: number;
1696-
documentURI?: string;
1697-
effectiveDirective?: string;
1696+
disposition: SecurityPolicyViolationEventDisposition;
1697+
documentURI: string;
1698+
effectiveDirective: string;
16981699
lineNumber?: number;
1699-
originalPolicy?: string;
1700+
originalPolicy: string;
17001701
referrer?: string;
1702+
sample?: string;
17011703
sourceFile?: string;
1702-
statusCode?: number;
1703-
violatedDirective?: string;
1704+
statusCode: number;
1705+
violatedDirective: string;
17041706
}
17051707

17061708
interface ShadowRootInit {
@@ -2620,6 +2622,25 @@ declare var CDATASection: {
26202622
new(): CDATASection;
26212623
};
26222624

2625+
interface CSPViolationReportBody extends ReportBody {
2626+
readonly blockedURL: string | null;
2627+
readonly columnNumber: number | null;
2628+
readonly disposition: SecurityPolicyViolationEventDisposition;
2629+
readonly documentURL: string;
2630+
readonly effectiveDirective: string;
2631+
readonly lineNumber: number | null;
2632+
readonly originalPolicy: string;
2633+
readonly referrer: string | null;
2634+
readonly sample: string | null;
2635+
readonly sourceFile: string | null;
2636+
readonly statusCode: number;
2637+
}
2638+
2639+
declare var CSPViolationReportBody: {
2640+
prototype: CSPViolationReportBody;
2641+
new(): CSPViolationReportBody;
2642+
};
2643+
26232644
/** A single condition CSS at-rule, which consists of a condition and a statement block. It is a child of CSSGroupingRule. */
26242645
interface CSSConditionRule extends CSSGroupingRule {
26252646
conditionText: string;
@@ -3662,6 +3683,16 @@ declare var CountQueuingStrategy: {
36623683
new(init: QueuingStrategyInit): CountQueuingStrategy;
36633684
};
36643685

3686+
interface CrashReportBody extends ReportBody {
3687+
readonly crashId: string;
3688+
readonly reason: string | null;
3689+
}
3690+
3691+
declare var CrashReportBody: {
3692+
prototype: CrashReportBody;
3693+
new(): CrashReportBody;
3694+
};
3695+
36653696
interface Credential {
36663697
readonly id: string;
36673698
readonly type: string;
@@ -4304,6 +4335,20 @@ declare var DelayNode: {
43044335
new(context: BaseAudioContext, options?: DelayOptions): DelayNode;
43054336
};
43064337

4338+
interface DeprecationReportBody extends ReportBody {
4339+
readonly anticipatedRemoval: Date | null;
4340+
readonly columnNumber: number | null;
4341+
readonly id: string;
4342+
readonly lineNumber: number | null;
4343+
readonly message: string;
4344+
readonly sourceFile: string | null;
4345+
}
4346+
4347+
declare var DeprecationReportBody: {
4348+
prototype: DeprecationReportBody;
4349+
new(): DeprecationReportBody;
4350+
};
4351+
43074352
/** Provides information about the amount of acceleration the device is experiencing along all three axes. */
43084353
interface DeviceAcceleration {
43094354
readonly x: number | null;
@@ -9621,6 +9666,19 @@ declare var IntersectionObserverEntry: {
96219666
new(intersectionObserverEntryInit: IntersectionObserverEntryInit): IntersectionObserverEntry;
96229667
};
96239668

9669+
interface InterventionReportBody extends ReportBody {
9670+
readonly columnNumber: number | null;
9671+
readonly id: string;
9672+
readonly lineNumber: number | null;
9673+
readonly message: string;
9674+
readonly sourceFile: string | null;
9675+
}
9676+
9677+
declare var InterventionReportBody: {
9678+
prototype: InterventionReportBody;
9679+
new(): InterventionReportBody;
9680+
};
9681+
96249682
/** KeyboardEvent objects describe a user interaction with the keyboard; each event describes a single interaction between the user and a key (or combination of a key with modifier keys) on the keyboard. */
96259683
interface KeyboardEvent extends UIEvent {
96269684
readonly altKey: boolean;
@@ -12436,6 +12494,25 @@ interface ReadableStreamGenericReader {
1243612494
cancel(reason?: any): Promise<void>;
1243712495
}
1243812496

12497+
interface Report {
12498+
readonly body: ReportBody | null;
12499+
readonly type: string;
12500+
readonly url: string;
12501+
}
12502+
12503+
declare var Report: {
12504+
prototype: Report;
12505+
new(): Report;
12506+
};
12507+
12508+
interface ReportBody {
12509+
}
12510+
12511+
declare var ReportBody: {
12512+
prototype: ReportBody;
12513+
new(): ReportBody;
12514+
};
12515+
1243912516
/** This Fetch API interface represents a resource request. */
1244012517
interface Request extends Body {
1244112518
/**
@@ -14660,11 +14737,13 @@ declare var ScriptProcessorNode: {
1466014737
interface SecurityPolicyViolationEvent extends Event {
1466114738
readonly blockedURI: string;
1466214739
readonly columnNumber: number;
14740+
readonly disposition: SecurityPolicyViolationEventDisposition;
1466314741
readonly documentURI: string;
1466414742
readonly effectiveDirective: string;
1466514743
readonly lineNumber: number;
1466614744
readonly originalPolicy: string;
1466714745
readonly referrer: string;
14746+
readonly sample: string;
1466814747
readonly sourceFile: string;
1466914748
readonly statusCode: number;
1467014749
readonly violatedDirective: string;
@@ -19833,6 +19912,7 @@ type ScrollBehavior = "auto" | "smooth";
1983319912
type ScrollLogicalPosition = "center" | "end" | "nearest" | "start";
1983419913
type ScrollRestoration = "auto" | "manual";
1983519914
type ScrollSetting = "" | "up";
19915+
type SecurityPolicyViolationEventDisposition = "enforce" | "report";
1983619916
type SelectionMode = "end" | "preserve" | "select" | "start";
1983719917
type ServiceWorkerState = "activated" | "activating" | "installed" | "installing" | "parsed" | "redundant";
1983819918
type ServiceWorkerUpdateViaCache = "all" | "imports" | "none";

baselines/webworker.generated.d.ts

+37
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,21 @@ interface RsaPssParams extends Algorithm {
501501
saltLength: number;
502502
}
503503

504+
interface SecurityPolicyViolationEventInit extends EventInit {
505+
blockedURI?: string;
506+
columnNumber?: number;
507+
disposition: SecurityPolicyViolationEventDisposition;
508+
documentURI: string;
509+
effectiveDirective: string;
510+
lineNumber?: number;
511+
originalPolicy: string;
512+
referrer?: string;
513+
sample?: string;
514+
sourceFile?: string;
515+
statusCode: number;
516+
violatedDirective: string;
517+
}
518+
504519
interface StorageEstimate {
505520
quota?: number;
506521
usage?: number;
@@ -2851,6 +2866,27 @@ declare var Response: {
28512866
redirect(url: string, status?: number): Response;
28522867
};
28532868

2869+
/** Inherits from Event, and represents the event object of an event sent on a document or worker when its content security policy is violated. */
2870+
interface SecurityPolicyViolationEvent extends Event {
2871+
readonly blockedURI: string;
2872+
readonly columnNumber: number;
2873+
readonly disposition: SecurityPolicyViolationEventDisposition;
2874+
readonly documentURI: string;
2875+
readonly effectiveDirective: string;
2876+
readonly lineNumber: number;
2877+
readonly originalPolicy: string;
2878+
readonly referrer: string;
2879+
readonly sample: string;
2880+
readonly sourceFile: string;
2881+
readonly statusCode: number;
2882+
readonly violatedDirective: string;
2883+
}
2884+
2885+
declare var SecurityPolicyViolationEvent: {
2886+
prototype: SecurityPolicyViolationEvent;
2887+
new(type: string, eventInitDict?: SecurityPolicyViolationEventInit): SecurityPolicyViolationEvent;
2888+
};
2889+
28542890
interface ServiceWorkerEventMap extends AbstractWorkerEventMap {
28552891
"statechange": Event;
28562892
}
@@ -5983,6 +6019,7 @@ type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin";
59836019
type RequestRedirect = "error" | "follow" | "manual";
59846020
type ResizeQuality = "high" | "low" | "medium" | "pixelated";
59856021
type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
6022+
type SecurityPolicyViolationEventDisposition = "enforce" | "report";
59866023
type ServiceWorkerState = "activated" | "activating" | "installed" | "installing" | "parsed" | "redundant";
59876024
type ServiceWorkerUpdateViaCache = "all" | "imports" | "none";
59886025
type VisibilityState = "hidden" | "visible";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[Exposed=Window]
2+
interface CSPViolationReportBody : ReportBody {
3+
readonly attribute USVString documentURL;
4+
readonly attribute USVString? referrer;
5+
readonly attribute USVString? blockedURL;
6+
readonly attribute DOMString effectiveDirective;
7+
readonly attribute DOMString originalPolicy;
8+
readonly attribute USVString? sourceFile;
9+
readonly attribute DOMString? sample;
10+
readonly attribute SecurityPolicyViolationEventDisposition disposition;
11+
readonly attribute unsigned short statusCode;
12+
readonly attribute unsigned long? lineNumber;
13+
readonly attribute unsigned long? columnNumber;
14+
};
15+
16+
enum SecurityPolicyViolationEventDisposition {
17+
"enforce", "report"
18+
};
19+
20+
[Exposed=(Window,Worker)]
21+
interface SecurityPolicyViolationEvent : Event {
22+
constructor(DOMString type, optional SecurityPolicyViolationEventInit eventInitDict = {});
23+
readonly attribute USVString documentURI;
24+
readonly attribute USVString referrer;
25+
readonly attribute USVString blockedURI;
26+
readonly attribute DOMString effectiveDirective;
27+
readonly attribute DOMString violatedDirective; // historical alias of effectiveDirective
28+
readonly attribute DOMString originalPolicy;
29+
readonly attribute USVString sourceFile;
30+
readonly attribute DOMString sample;
31+
readonly attribute SecurityPolicyViolationEventDisposition disposition;
32+
readonly attribute unsigned short statusCode;
33+
readonly attribute unsigned long lineNumber;
34+
readonly attribute unsigned long columnNumber;
35+
};
36+
37+
dictionary SecurityPolicyViolationEventInit : EventInit {
38+
required USVString documentURI;
39+
USVString referrer = "";
40+
USVString blockedURI = "";
41+
required DOMString violatedDirective;
42+
required DOMString effectiveDirective;
43+
required DOMString originalPolicy;
44+
USVString sourceFile = "";
45+
DOMString sample = "";
46+
required SecurityPolicyViolationEventDisposition disposition;
47+
required unsigned short statusCode;
48+
unsigned long lineNumber = 0;
49+
unsigned long columnNumber = 0;
50+
};

inputfiles/idl/Reporting.widl

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
interface ReportBody {
2+
};
3+
4+
interface Report {
5+
readonly attribute DOMString type;
6+
readonly attribute DOMString url;
7+
readonly attribute ReportBody? body;
8+
};
9+
10+
[Constructor(ReportingObserverCallback callback, optional ReportingObserverOptions options)]
11+
interface ReportingObserver {
12+
void observe();
13+
void disconnect();
14+
ReportList takeRecords();
15+
};
16+
17+
callback ReportingObserverCallback = void (sequence<Report> reports, ReportingObserver observer);
18+
19+
dictionary ReportingObserverOptions {
20+
sequence<DOMString> types;
21+
boolean buffered = false;
22+
};
23+
24+
typedef sequence<Report> ReportList;
25+
26+
interface DeprecationReportBody : ReportBody {
27+
readonly attribute DOMString id;
28+
readonly attribute Date? anticipatedRemoval;
29+
readonly attribute DOMString message;
30+
readonly attribute DOMString? sourceFile;
31+
readonly attribute unsigned long? lineNumber;
32+
readonly attribute unsigned long? columnNumber;
33+
};
34+
35+
interface InterventionReportBody : ReportBody {
36+
readonly attribute DOMString id;
37+
readonly attribute DOMString message;
38+
readonly attribute DOMString? sourceFile;
39+
readonly attribute unsigned long? lineNumber;
40+
readonly attribute unsigned long? columnNumber;
41+
};
42+
43+
interface CrashReportBody : ReportBody {
44+
readonly attribute DOMString crashId;
45+
readonly attribute DOMString? reason;
46+
};
47+
48+
dictionary GenerateTestReportParameters {
49+
required DOMString message;
50+
DOMString group;
51+
};

inputfiles/idlSources.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -697,5 +697,13 @@
697697
{
698698
"url": "https://html.spec.whatwg.org/multipage/web-messaging.html",
699699
"title": "Web Messaging"
700+
},
701+
{
702+
"url": "https://www.w3.org/TR/CSP3",
703+
"title": "Content Security Policy Level 3"
704+
},
705+
{
706+
"url": "https://www.w3.org/TR/reporting/",
707+
"title": "Reporting"
700708
}
701-
]
709+
]

0 commit comments

Comments
 (0)