Function bodies 22 total
PolicyMaker class · typescript · L30-L334 (305 LOC)store/index.ts
export class PolicyMaker extends VuexModule {
// Wizard
currentStep: number = 1
navSteps: NavSteps = [
{ route: '/policymaker/introduction', name: 'Introduction' },
{ route: '/policymaker/organization', name: 'Organization details' },
{ route: '/policymaker/settings', name: 'Policy settings' },
{ route: '/policymaker/download', name: 'Download' }
]
downloadSections: NavSteps = [
{ route: '/policymaker/download/vdp', name: 'Vulnerability Disclosure Policy' },
{ route: '/policymaker/download/securitytxt', name: 'Security.txt' },
{ route: '/policymaker/download/dnssecuritytxt', name: 'DNS Security.txt' },
]
// Policy settings
policyConfiguration: PolicyConfiguration = {
language: 'en-US',
organizationName: '',
organizationDomain: '',
channels: <Channels>[{ prefix: '', type: '', address: '' }],
cvdTimelineDays: 90,
hostUrl: {
prefix: 'https://',
type: 'url',
address: ''
}
}
vdpLanguageOptionssetStep method · typescript · L153-L155 (3 LOC)store/index.ts
setStep(stepNumber: number) {
this.currentStep = stepNumber
}setOrganizationName method · typescript · L158-L160 (3 LOC)store/index.ts
setOrganizationName(name: string) {
this.policyConfiguration.organizationName = name
}setOrganizationDomain method · typescript · L163-L165 (3 LOC)store/index.ts
setOrganizationDomain(domain: string) {
this.policyConfiguration.organizationDomain = domain.trim()
}addChannel method · typescript · L168-L174 (7 LOC)store/index.ts
addChannel(channel?: Channel) {
if (channel) {
this.policyConfiguration.channels.push(channel)
} else {
this.policyConfiguration.channels.push({ prefix: '', type: '', address: '' })
}
}removeChannel method · typescript · L177-L179 (3 LOC)store/index.ts
removeChannel(index: number) {
this.policyConfiguration.channels.splice(index, 1)
}setLanguage method · typescript · L182-L184 (3 LOC)store/index.ts
setLanguage(language: string) {
this.policyConfiguration.language = language
}Repobility — the code-quality scanner for AI-generated software · https://repobility.com
setCVDTimelineDays method · typescript · L187-L189 (3 LOC)store/index.ts
setCVDTimelineDays(days: number) {
this.policyConfiguration.cvdTimelineDays = days
}setTemplateText method · typescript · L192-L203 (12 LOC)store/index.ts
setTemplateText(request: SetTemplateTextRequest) {
// Check if language is loaded
if (!this.tpls.vdp.hasOwnProperty(request.language)) {
this.tpls.vdp[request.language] = {
base: "",
with_cvd: "",
safe_harbor: ""
}
}
this.tpls.vdp[request.language][request.type] = request.text
}setSecurityTxt method · typescript · L206-L208 (3 LOC)store/index.ts
setSecurityTxt(text: string) {
this.tpls.securitytxt.base = text
}setHostUrl method · typescript · L211-L213 (3 LOC)store/index.ts
setHostUrl(channel: Channel) {
this.policyConfiguration.hostUrl = channel
}setVDPLanguageOptions method · typescript · L216-L218 (3 LOC)store/index.ts
setVDPLanguageOptions(languages: Array<string>) {
this.vdpLanguageOptions = languages
}setVDPTemplatesForLanguage method · typescript · L221-L223 (3 LOC)store/index.ts
setVDPTemplatesForLanguage(templateSet: VDPLanguageTemplateSet) {
this.tpls.vdp[templateSet.language] = cloneDeep(templateSet.templates)
}updateLanguage method · typescript · L226-L231 (6 LOC)store/index.ts
updateLanguage(lang: string) {
this.fetchTerms(lang).then(() => {
this.context.commit("setLanguage", lang)
})
}fetchSecurityTxt method · typescript · L234-L285 (52 LOC)store/index.ts
async fetchSecurityTxt() {
// Check if needs loading
if (!_isEmpty(this.tpls.securitytxt.base)) {
return Promise.resolve(true)
}
// During static generation, use a default template
if (process.static) {
this.setSecurityTxt(`# {{organization}} security contacts and policy
# Our security contact channels
{{channel}}
# Link to our vulnerability disclosure policy
Policy: {{policy_url}}
# Languages that our team speaks and understands
Preferred-Languages: {{languages}}
# Expiration date for this security.txt file
Expires: {{expires}}
`)
return Promise.resolve(true)
}
// During runtime, fetch from server
const base = (this.context as any)?.app?.$router?.options?.base || ''
const url = `${base}/templates/securitytxt/securitytxt.md`
try {
const response = await fetch(url)
const text = await response.text()
this.setSecurityTxt(text)
} catch (error) {
console.error('Failed to fetch security.txt templatWant fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
fetchLanguages method · typescript · L288-L294 (7 LOC)store/index.ts
async fetchLanguages() {
// @ts-ignore
let url = `${$nuxt.$router.options.base}templates/languages.json`
const response = await fetch(url)
const responseJson = await response.json()
this.setVDPLanguageOptions(responseJson.languages)
}syncStepFromRoute method · typescript · L297-L304 (8 LOC)store/index.ts
syncStepFromRoute(route: string) {
let index = _findIndex(this.context.getters['getNavSteps'], (step: NavStep) => {
return _startsWith(route, step.route)
})
index++
this.context.commit('setStep', index)
}fetchTerms method · typescript · L307-L333 (27 LOC)store/index.ts
async fetchTerms(lang: string) {
let langToLoad: string = lang
if (_isEmpty(lang)) {
langToLoad = this.policyConfiguration.language
}
// Check if needs loading
if (this.tpls.vdp.hasOwnProperty(langToLoad)) {
return Promise.resolve(true)
}
return Promise.all(
_map(this.vdpTemplateBase, async (template, key: (keyof VDPTemplateSet)) => {
let url = `${$nuxt.$router.options.base}${template}`
url = url.replace("{{locale}}", langToLoad)
const response = await fetch(url)
const text = await response.text()
this.setTemplateText({
language: langToLoad,
type: key,
text
})
return true
})
)
}_map method · typescript · L319-L331 (13 LOC)store/index.ts
_map(this.vdpTemplateBase, async (template, key: (keyof VDPTemplateSet)) => {
let url = `${$nuxt.$router.options.base}${template}`
url = url.replace("{{locale}}", langToLoad)
const response = await fetch(url)
const text = await response.text()
this.setTemplateText({
language: langToLoad,
type: key,
text
})
return true
})renderTemplate function · typescript · L12-L36 (25 LOC)utils/mdTemplate.ts
export function renderTemplate(template: string, config: PolicyConfiguration) {
let policy = template || ""
let varRegex, newValue
// Replace Organisation Name
varRegex = new RegExp(`{{organization}}`, 'gm')
newValue = config.organizationName
policy = policy.replace(varRegex, newValue)
// Replace Channels
varRegex = new RegExp(`{{channel}}`, 'gm');
const channels = channelURIs(config.channels)
newValue = _join(channels, " or ")
policy = policy.replace(varRegex, newValue)
// Replace CVD Timeline
varRegex = new RegExp(`{{disclosure_window}}`, 'gm')
newValue = `${config.cvdTimelineDays}`
policy = policy.replace(varRegex, newValue)
return policy
}renderSecurityTxt function · typescript · L38-L75 (38 LOC)utils/mdTemplate.ts
export function renderSecurityTxt(template: string, config: PolicyConfiguration) {
let securitytxt = template || ""
let varRegex, newValue
// Replace Organisation Name
varRegex = new RegExp(`{{organization}}`, 'gm');
newValue = config.organizationName
securitytxt = securitytxt.replace(varRegex, newValue)
// Replace Channels
varRegex = new RegExp(`{{channel}}`, 'gm');
const channels = channelURIs(config.channels)
newValue = _join(_map(channels, (channel) => {
return `Contact: ${channel}`
}), "\n")
securitytxt = securitytxt.replace(varRegex, newValue)
// Replace Policy URL
varRegex = new RegExp(`{{policy_url}}`, 'gm');
const hostURI = channelURIs([config.hostUrl])
newValue = _join(hostURI, "")
securitytxt = securitytxt.replace(varRegex, newValue)
// Replace language
varRegex = new RegExp(`{{languages}}`, 'gm');
securitytxt = securitytxt.replace(varRegex, config.language)
// Replace expires field with a date 1 year in the future
varRchannelURIs function · typescript · L78-L83 (6 LOC)utils/mdTemplate.ts
export function channelURIs(channels: Channels): Array<string> {
return _map(channels, (channel: Channel) => {
return `${channel.prefix.trim()}${channel.address.trim()}`
})
}