Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions data/datacreator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* Copyright (c) 2014-2023 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -49,6 +49,7 @@
createSecurityQuestions,
createUsers,
createChallenges,
createChallenges3,
createRandomFakeUsers,
createProducts,
createBaskets,
Expand Down Expand Up @@ -104,6 +105,42 @@
)
}

async function createChallenges3 () {
const showHints = config.get('challenges.showHints')
const showMitigations = config.get('challenges.showMitigations')

const challenges = await loadStaticData('challenges')

await Promise.all(
challenges.map(async ({ name, category, description, difficulty, hint, hintUrl, mitigationUrl, key, disabledEnv, tutorial, tags }: Challenge) => {
const effectiveDisabledEnv = utils.determineDisabledEnv(disabledEnv)
description = description.replace('juice-sh.op', config.get('application.domain'))
description = description.replace('<iframe width="100%" height="166" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/771984076&color=%23ff5500&auto_play=true&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true"></iframe>', entities.encode(config.get('challenges.xssBonusPayload')))
hint = hint.replace(/OWASP Juice Shop's/, `${config.get('application.name')}'s`)

try {
datacache.challenges[key] = await ChallengeModel.create({
key,
name,
category,
tags: tags ? tags.join(',') : undefined,
description: effectiveDisabledEnv ? (description + ' <em>(This challenge is <strong>' + (config.get('challenges.safetyOverride') ? 'potentially harmful' : 'not available') + '</strong> on ' + effectiveDisabledEnv + '!)</em>') : description,
difficulty,
solved: false,
hint: showHints ? hint : null,
hintUrl: showHints ? hintUrl : null,
mitigationUrl: showMitigations ? mitigationUrl : null,
disabledEnv: config.get<boolean>('challenges.safetyOverride') ? null : effectiveDisabledEnv,
tutorialOrder: tutorial ? tutorial.order : null,
codingChallengeStatus: 0
})
} catch (err) {
logger.error(`Could not insert Challenge ${name}: ${utils.getErrorMessage(err)}`)
}
})
)
}

async function createUsers () {
const users = await loadStaticData('users')

Expand Down
Loading