@angular/core#SecurityContext TypeScript Examples

The following examples show how to use @angular/core#SecurityContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: map-util.service.ts    From EDA with GNU Affero General Public License v3.0 7 votes vote down vote up
private makePopup = (data: any, labels: Array<string>): string => {
        const me = this;
        let div = '';
        for (let i = 2; i < 4; i++) {
            if (data[i] !== undefined) {
                div += `<div> ${me._sanitizer.sanitize(SecurityContext.HTML, labels[i])} :  ${data[i]} </div>`;
            }
        }
        return `` + div;
    }
Example #2
Source File: map-util.service.ts    From EDA with GNU Affero General Public License v3.0 7 votes vote down vote up
public makeGeoJsonPopup = (layer_id: string, data: Array<number>, labels: Array<string>, labelIndex: number, totalSum:number): string => {
        const me = this;
        let row = data.filter(row => row[labelIndex] !== null &&  this.labelProcessingHelper( row[labelIndex] ) === this.labelProcessingHelper( layer_id )   )[0];
        let div = '';
        for (let i = 0; i < labels.length; i++) {
            if (row !== undefined) {
                let value =
                    typeof row[i] === 'number' ?
                        `${parseFloat(row[i]).toLocaleString('de-DE', { maximumFractionDigits: 6 })} ( ${(parseFloat(row[i]) / totalSum * 100).toFixed(2)}% )`
                        : row[i];
                div += `<div> ${me._sanitizer.sanitize(SecurityContext.HTML, labels[i])} :  ${value} </div>`;
            } else {
                div = `<div> No data </div>`;
            }
        }
        return `` + div;
    }
Example #3
Source File: app-aws-authentication.service.ts    From leapp with Mozilla Public License 2.0 6 votes vote down vote up
async needAuthentication(idpUrl: string): Promise<boolean> {
    const sanitizedField = this.domSanitizer.sanitize(SecurityContext.URL, idpUrl);
    return new Promise((resolve) => {
      // Get active window position for extracting new windows coordinate
      const activeWindowPosition = this.windowService.getCurrentWindow().getPosition();
      const nearX = 200;
      const nearY = 50;
      // Generate a new singleton browser window for the check
      let idpWindow = this.windowService.newWindow(sanitizedField, false, "", activeWindowPosition[0] + nearX, activeWindowPosition[1] + nearY);

      // Our request filter call the generic hook filter passing the idp response type
      // to construct the ideal method to deal with the construction of the response
      idpWindow.webContents.session.webRequest.onBeforeRequest((details, callback) => {
        if (this.leappCoreService.authenticationService.isAuthenticationUrl(CloudProviderType.aws, details.url)) {
          idpWindow = null;
          resolve(true);
        }
        if (this.leappCoreService.authenticationService.isSamlAssertionUrl(CloudProviderType.aws, details.url)) {
          idpWindow = null;
          resolve(false);
        }
        // Callback is used by filter to keep traversing calls until one of the filters apply
        callback({
          requestHeaders: details.requestHeaders,
          url: details.url,
        });
      });
      // Start the process
      idpWindow.loadURL(sanitizedField);
    });
  }
Example #4
Source File: eda-geoJsonMap.component.ts    From EDA with GNU Affero General Public License v3.0 6 votes vote down vote up
private initLegend = (groups: Array<number>, label: string, color: string): void => {
    let me = this;
    label = me._sanitizer.sanitize(SecurityContext.HTML, label)
    this.legend.onAdd = function (map) {
      var div = L.DomUtil.create("div", "legend");
      L.DomUtil.addClass(div, 'map-legend');
      div.style.backgroundColor = "#ffffff38";
      div.style.borderRadius = "5%";
      div.innerHTML += `<h6 style="padding : 5px; padding-top:10px; padding-bottom:0px;font-weight:bold">
                        ${(label.charAt(0).toUpperCase() + label.slice(1)).replace(new RegExp('_', 'g'), ' ')} </h6>`;
      var div2 = L.DomUtil.create("div", "innerlegend", div);
      div2.style.padding = "3px";
      div2.style.textAlign = "left";
      div2.style.lineHeight = "1";
      let g = [...groups]; g.push(0);
      for (let i = g.length - 1; i > 0; i--) {
        let shade = i === 0 ? -80 : i === 1 ? -40 : i === 2 ? 0 : i === 3 ? 40 : 80;
        div2.innerHTML += `<span class="circle" style="color: ${me.colorShade(color, shade)}">
                          </span><span>&nbsp ${new Intl.NumberFormat("de-DE").format(Math.floor(g[i]))} - 
                          ${new Intl.NumberFormat("de-DE").format(Math.floor(g[i - 1]))}</span><br>`;
      }
      return div
    };

    this.legend.addTo(this.map);
  }
Example #5
Source File: content.service.ts    From open-source with MIT License 6 votes vote down vote up
compile(markdown: string, decodeHtml = false): string {
    const trimmed = this.trimIndentation(markdown);
    const decoded = decodeHtml ? this.decodeHtml(trimmed) : trimmed;
    const compiled = marked(decoded, {
      renderer: new marked.Renderer(),
      breaks: false,
      gfm: true,
      headerIds: true,
      silent: !isDevMode(),
      smartLists: true,
      smartypants: true,
      xhtml: true,
    });
    return this.sanitizer.sanitize(SecurityContext.HTML, compiled) || '';
  }
Example #6
Source File: download.component.ts    From open-genes-frontend with Mozilla Public License 2.0 6 votes vote down vote up
downloadFile(): void {
    this.apiService
      .getGeneByHGNCsymbol(this.data)
      .pipe(
        takeUntil(this.unsubscribe$)
      )
      .subscribe((gene) => {
        const downloadLink = document.createElement('a');
        downloadLink.href = this.sanitizer.sanitize(
          SecurityContext.RESOURCE_URL,
          this.fileExportService.downloadJson(gene)
        );
        downloadLink.setAttribute('download', 'export.json');
        downloadLink.setAttribute('target', '_blank');
        downloadLink.click();
      });
  }
Example #7
Source File: highlight.directive.ts    From open-genes-frontend with Mozilla Public License 2.0 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    if (this.el?.nativeElement) {
      if ('searchTerm' in changes || 'caseSensitive' in changes) {
        const text = (this.el.nativeElement as HTMLElement).textContent;
        if (this.searchTerm === '') {
          this.content = text;
        } else {
          const regex = new RegExp(this.searchTerm, this.caseSensitive ? 'g' : 'gi');
          const newText = text.replace(regex, (match: string) => {
            return `<mark class="text-highlight">${match}</mark>`;
          });
          const sanitzed = this.sanitizer.sanitize(SecurityContext.HTML, newText);
          this.content = sanitzed;
        }
      }
    }
  }
Example #8
Source File: shared.module.ts    From ledge with Mozilla Public License 2.0 6 votes vote down vote up
@NgModule({
  imports: [
    CommonModule,
    RouterModule,
    FormsModule,
    ReactiveFormsModule,
    HttpClientModule,
    CustomMaterialModule,
    LedgeRenderModule,
    LedgeViewModule,
    TranslateModule,
    MarkdownModule.forRoot({
      sanitize: SecurityContext.NONE,
      loader: HttpClient,
      markedOptions: {
        provide: MarkedOptions,
        useValue: {
          gfm: true,
          breaks: false,
          pedantic: false,
          smartLists: true,
          smartypants: false,
          langPrefix: 'language-',
          headerPrefix: '',
          headerIds: true,
        },
      },
    }),
  ],
  declarations: [],
  providers: [],
  exports: [LedgeViewModule],
  entryComponents: [],
})
export class SharedModule {}
Example #9
Source File: platformBrowserService.ts    From ngx-dynamic-hooks with MIT License 5 votes vote down vote up
sanitize(content: string): string {
    return this.sanitizer.sanitize(SecurityContext.HTML, content);
  }
Example #10
Source File: leapp-select.component.ts    From leapp with Mozilla Public License 2.0 5 votes vote down vote up
private checkCrossScriptingInjection(temporaryName: string): boolean {
    const sanitizedField = this.domSanitizer.sanitize(SecurityContext.URL, temporaryName);
    return sanitizedField.indexOf("unsafe:") > -1;
  }
Example #11
Source File: app-aws-authentication.service.ts    From leapp with Mozilla Public License 2.0 5 votes vote down vote up
async awsSignIn(idpUrl: string, needToAuthenticate: boolean): Promise<string> {
    const sanitizedField = this.domSanitizer.sanitize(SecurityContext.URL, idpUrl);
    // 1. Show or not browser window depending on needToAuthenticate
    const activeWindowPosition = this.windowService.getCurrentWindow().getPosition();
    const nearX = 200;
    const nearY = 50;
    // 2. Prepare browser window
    let idpWindow = this.windowService.newWindow(
      sanitizedField,
      needToAuthenticate,
      "IDP - Login",
      activeWindowPosition[0] + nearX,
      activeWindowPosition[1] + nearY
    );
    // Catch filter url: extract SAML response
    // Our request filter call the generic hook filter passing the idp response type
    // to construct the ideal method to deal with the construction of the response
    return new Promise((resolve) => {
      idpWindow.webContents.session.webRequest.onBeforeRequest((details, callback) => {
        if (this.leappCoreService.authenticationService.isSamlAssertionUrl(CloudProviderType.aws, details.url)) {
          // it will throw an error as we have altered the original response
          // Setting that everything is ok if we have arrived here
          idpWindow.close();
          idpWindow = null;

          // Shut down the filter action: we don't need it anymore
          if (callback) {
            callback({ cancel: true });
          }

          // Return the details
          resolve(this.leappCoreService.authenticationService.extractAwsSamlResponse(details));
        } else {
          // Callback is used by filter to keep traversing calls until one of the filters apply
          callback({
            requestHeaders: details.requestHeaders,
            url: details.url,
          });
        }
      });
      // 4. Navigate to idpUrl
      idpWindow.loadURL(sanitizedField);
    });
  }
Example #12
Source File: app-aws-authentication.service.ts    From leapp with Mozilla Public License 2.0 5 votes vote down vote up
async logoutFromFederatedSession(session: Session, callback?: any): Promise<void> {
    try {
      // Clear all extra data
      const url = this.leappCoreService.idpUrlService.getIdpUrl((session as AwsIamRoleFederatedSession).idpUrlId);
      const sanitizedField = this.domSanitizer.sanitize(SecurityContext.URL, url);

      const getAppPath = this.electronService.path.join(this.electronService.app.getPath("appData"), constants.appName);
      this.electronService.rimraf.sync(getAppPath + `/Partitions/leapp-${btoa(sanitizedField)}`);

      if (session) {
        const sessionService = this.leappCoreService.sessionFactory.getSessionService(session.type);
        await sessionService.stop(session.sessionId);
        if (callback) {
          callback();
        }
      }

      this.leappCoreService.logService.log(
        new LoggedEntry("Cache and configuration file cleaned. Stopping session and restarting Leapp to take effect.", this, LogLevel.info, true)
      );

      // Restart
      setTimeout(() => {
        // a bit of timeout to make everything reset as expected and give time to read message
        this.appService.restart();
      }, 3000);
    } catch (err) {
      this.leappCoreService.logService.log(
        new LoggedEntry("Leapp has an error re-creating your configuration file and cache.", this, LogLevel.error, false, err.stack)
      );
      if (this.appService.detectOs() === constants.windows) {
        this.leappCoreService.logService.log(
          new LoggedEntry(
            "Leapp needs Admin permissions to do this: please restart the application as an Administrator and retry.",
            this,
            LogLevel.warn,
            true
          )
        );
      } else {
        this.leappCoreService.logService.log(
          new LoggedEntry("Leapp has an error re-creating your configuration file and cache.", this, LogLevel.error, true)
        );
      }
    }
  }
Example #13
Source File: update-details.component.ts    From dev-manager-desktop with Apache License 2.0 5 votes vote down vote up
constructor(@Inject('release') public release: Release, sanitizer: DomSanitizer) {
    this.bodyHtml = sanitizer.sanitize(SecurityContext.HTML, marked(release.body || 'No description.'));
  }