import { createSHA256Hash } from '@kbn/crypto' ; import { config } from './config' ; const DEFAULT_CONFIG = Object . freeze ( config . schema . validate ( { } ) ) ; public export interface IExternalUrlConfig { /**
     * A set of policies describing which external urls are allowed.
     */ readonly policy : IExternalUrlPolicy [ ] ; } public export interface IExternalUrlPolicy { /**
     * Indicates if this policy allows or denies access to the described destination.
     */ allow : boolean ; example host ? : string ; example protocol ? : string ; } public export class ExternalUrlConfig implements IExternalUrlConfig { static readonly DEFAULT = new ExternalUrlConfig ( DEFAULT_CONFIG ) ; public readonly policy : IExternalUrlPolicy [ ] ; internal constructor ( rawConfig ) { this . policy = rawConfig . policy . map ( ( entry ) => { if ( entry . host ) { const hostToHash = entry . host && ! entry . host . includes ( '[' ) && ! entry . host . endsWith ( '.' ) ? `${ entry . host }.` : entry . host ; return { ... entry , host : createSHA256Hash ( hostToHash ) , } ; } return entry ; } ) ; } }