Skip to content

Commit

Permalink
Merge pull request #15966 from primefaces/issue-15965
Browse files Browse the repository at this point in the history
Fixes #15965 - Fix order of actions for CSP
  • Loading branch information
cetincakiroglu authored Jul 5, 2024
2 parents be604c0 + 28ed953 commit e804cd6
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 64 deletions.
12 changes: 2 additions & 10 deletions src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,15 +1169,7 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
return this.currentView === 'year' ? this.getTranslation('nextDecade') : this.currentView === 'month' ? this.getTranslation('nextYear') : this.getTranslation('nextMonth');
}

constructor(
@Inject(DOCUMENT) private document: Document,
public el: ElementRef,
public renderer: Renderer2,
public cd: ChangeDetectorRef,
private zone: NgZone,
private config: PrimeNGConfig,
public overlayService: OverlayService
) {
constructor(@Inject(DOCUMENT) private document: Document, public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, private zone: NgZone, private config: PrimeNGConfig, public overlayService: OverlayService) {
this.window = this.document.defaultView as Window;
}

Expand Down Expand Up @@ -3544,6 +3536,7 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
if (!this.responsiveStyleElement) {
this.responsiveStyleElement = this.renderer.createElement('style');
(<HTMLStyleElement>this.responsiveStyleElement).type = 'text/css';
DomHandler.setAttribute(this.responsiveStyleElement, 'nonce', this.config?.csp()?.nonce);
this.renderer.appendChild(this.document.body, this.responsiveStyleElement);
}

Expand Down Expand Up @@ -3576,7 +3569,6 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
}

(<HTMLStyleElement>this.responsiveStyleElement).innerHTML = innerHTML;
DomHandler.setAttribute(this.responsiveStyleElement, 'nonce', this.config?.csp()?.nonce);
}
}

Expand Down
10 changes: 1 addition & 9 deletions src/app/components/carousel/carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,7 @@ export class Carousel implements AfterContentInit {

window: Window;

constructor(
public el: ElementRef,
public zone: NgZone,
public cd: ChangeDetectorRef,
private renderer: Renderer2,
@Inject(DOCUMENT) private document: Document,
@Inject(PLATFORM_ID) private platformId: any,
private config: PrimeNGConfig
) {
constructor(public el: ElementRef, public zone: NgZone, public cd: ChangeDetectorRef, private renderer: Renderer2, @Inject(DOCUMENT) private document: Document, @Inject(PLATFORM_ID) private platformId: any, private config: PrimeNGConfig) {
this.totalShiftedItems = this.page * this.numScroll * -1;
this.window = this.document.defaultView as Window;
}
Expand Down
12 changes: 2 additions & 10 deletions src/app/components/confirmdialog/confirmdialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,7 @@ export class ConfirmDialog implements AfterContentInit, OnInit, OnDestroy {

translationSubscription: Subscription | undefined;

constructor(
public el: ElementRef,
public renderer: Renderer2,
private confirmationService: ConfirmationService,
public zone: NgZone,
private cd: ChangeDetectorRef,
public config: PrimeNGConfig,
@Inject(DOCUMENT) private document: Document
) {
constructor(public el: ElementRef, public renderer: Renderer2, private confirmationService: ConfirmationService, public zone: NgZone, private cd: ChangeDetectorRef, public config: PrimeNGConfig, @Inject(DOCUMENT) private document: Document) {
this.subscription = this.confirmationService.requireConfirmation$.subscribe((confirmation) => {
if (!confirmation) {
this.hide();
Expand Down Expand Up @@ -611,6 +603,7 @@ export class ConfirmDialog implements AfterContentInit, OnInit, OnDestroy {
if (!this.styleElement) {
this.styleElement = this.document.createElement('style');
this.styleElement.type = 'text/css';
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
this.document.head.appendChild(this.styleElement);
let innerHTML = '';
for (let breakpoint in this.breakpoints) {
Expand All @@ -624,7 +617,6 @@ export class ConfirmDialog implements AfterContentInit, OnInit, OnDestroy {
}

this.styleElement.innerHTML = innerHTML;
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
}
}

Expand Down
12 changes: 2 additions & 10 deletions src/app/components/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,7 @@ export class Dialog implements AfterContentInit, OnInit, OnDestroy {
return this.config.getTranslation(TranslationKeys.ARIA)['maximizeLabel'];
}

constructor(
@Inject(DOCUMENT) private document: Document,
@Inject(PLATFORM_ID) private platformId: any,
public el: ElementRef,
public renderer: Renderer2,
public zone: NgZone,
private cd: ChangeDetectorRef,
public config: PrimeNGConfig
) {
constructor(@Inject(DOCUMENT) private document: Document, @Inject(PLATFORM_ID) private platformId: any, public el: ElementRef, public renderer: Renderer2, public zone: NgZone, private cd: ChangeDetectorRef, public config: PrimeNGConfig) {
this.window = this.document.defaultView as Window;
}

Expand Down Expand Up @@ -696,6 +688,7 @@ export class Dialog implements AfterContentInit, OnInit, OnDestroy {
if (!this.styleElement) {
this.styleElement = this.renderer.createElement('style');
this.styleElement.type = 'text/css';
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
this.renderer.appendChild(this.document.head, this.styleElement);
let innerHTML = '';
for (let breakpoint in this.breakpoints) {
Expand All @@ -709,7 +702,6 @@ export class Dialog implements AfterContentInit, OnInit, OnDestroy {
}

this.renderer.setProperty(this.styleElement, 'innerHTML', innerHTML);
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/orderlist/orderlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ export class OrderList implements AfterViewChecked, AfterContentInit {
this.renderer.setAttribute(this.el.nativeElement.children[0], this.id, '');
this.styleElement = this.renderer.createElement('style');
this.renderer.setAttribute(this.styleElement, 'type', 'text/css');
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
this.renderer.appendChild(this.document.head, this.styleElement);

let innerHTML = `
Expand All @@ -937,7 +938,6 @@ export class OrderList implements AfterViewChecked, AfterContentInit {
}
`;
this.renderer.setProperty(this.styleElement, 'innerHTML', innerHTML);
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/picklist/picklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,7 @@ export class PickList implements AfterViewChecked, AfterContentInit {
this.renderer.setAttribute(this.el.nativeElement.children[0], this.id, '');
this.styleElement = this.renderer.createElement('style');
this.renderer.setAttribute(this.styleElement, 'type', 'text/css');
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
this.renderer.appendChild(this.document.head, this.styleElement);

let innerHTML = `
Expand All @@ -1650,7 +1651,6 @@ export class PickList implements AfterViewChecked, AfterContentInit {
}`;

this.renderer.setProperty(this.styleElement, 'innerHTML', innerHTML);
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2974,8 +2974,8 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable
createStyleElement() {
this.styleElement = this.renderer.createElement('style');
this.styleElement.type = 'text/css';
this.renderer.appendChild(this.document.head, this.styleElement);
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
this.renderer.appendChild(this.document.head, this.styleElement);
}

getGroupRowsMeta() {
Expand All @@ -2987,8 +2987,8 @@ export class Table implements OnInit, AfterViewInit, AfterContentInit, Blockable
if (!this.responsiveStyleElement) {
this.responsiveStyleElement = this.renderer.createElement('style');
this.responsiveStyleElement.type = 'text/css';
this.renderer.appendChild(this.document.head, this.responsiveStyleElement);
DomHandler.setAttribute(this.responsiveStyleElement, 'nonce', this.config?.csp()?.nonce);
this.renderer.appendChild(this.document.head, this.responsiveStyleElement);

let innerHTML = `
@media screen and (max-width: ${this.breakpoint}) {
Expand Down
30 changes: 9 additions & 21 deletions src/app/components/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ export class ToastItem implements AfterViewInit, OnDestroy {

timeout: any;

constructor(
private zone: NgZone,
private config: PrimeNGConfig
) {}
constructor(private zone: NgZone, private config: PrimeNGConfig) {}

ngAfterViewInit() {
this.initTimeout();
Expand All @@ -162,15 +159,12 @@ export class ToastItem implements AfterViewInit, OnDestroy {
initTimeout() {
if (!this.message?.sticky) {
this.zone.runOutsideAngular(() => {
this.timeout = setTimeout(
() => {
this.onClose.emit({
index: <number>this.index,
message: <Message>this.message
});
},
this.message?.life || this.life || 3000
);
this.timeout = setTimeout(() => {
this.onClose.emit({
index: <number>this.index,
message: <Message>this.message
});
}, this.message?.life || this.life || 3000);
});
}
}
Expand Down Expand Up @@ -349,13 +343,7 @@ export class Toast implements OnInit, AfterContentInit, OnDestroy {

_position: ToastPositionType = 'top-right';

constructor(
@Inject(DOCUMENT) private document: Document,
private renderer: Renderer2,
public messageService: MessageService,
private cd: ChangeDetectorRef,
public config: PrimeNGConfig
) {}
constructor(@Inject(DOCUMENT) private document: Document, private renderer: Renderer2, public messageService: MessageService, private cd: ChangeDetectorRef, public config: PrimeNGConfig) {}

styleElement: any;

Expand Down Expand Up @@ -476,6 +464,7 @@ export class Toast implements OnInit, AfterContentInit, OnDestroy {
if (!this.styleElement) {
this.styleElement = this.renderer.createElement('style');
this.styleElement.type = 'text/css';
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
this.renderer.appendChild(this.document.head, this.styleElement);
let innerHTML = '';
for (let breakpoint in this.breakpoints) {
Expand All @@ -493,7 +482,6 @@ export class Toast implements OnInit, AfterContentInit, OnDestroy {
}

this.renderer.setProperty(this.styleElement, 'innerHTML', innerHTML);
DomHandler.setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
}
}

Expand Down

0 comments on commit e804cd6

Please sign in to comment.