-
Notifications
You must be signed in to change notification settings - Fork 1
Cydor test #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Cydor test #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| /* | ||
| * Copyright (c) 2014-2023 Bjoern Kimminich & the OWASP Juice Shop contributors. | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| import models = require('../models/index') | ||
| import { type Request, type Response, type NextFunction } from 'express' | ||
| import { UserModel } from '../models/user' | ||
|
|
||
| import * as utils from '../lib/utils' | ||
| const challengeUtils = require('../lib/challengeUtils') | ||
| const challenges = require('../data/datacache').challenges | ||
|
|
||
| class ErrorWithParent extends Error { | ||
| parent: Error | undefined | ||
| } | ||
|
|
||
| // vuln-code-snippet start unionSqlInjectionChallenge dbSchemaChallenge | ||
| module.exports = function searchProducts () { | ||
| return (req: Request, res: Response, next: NextFunction) => { | ||
| let criteria: any = req.query.q === 'undefined' ? '' : req.query.q ?? '' | ||
| criteria = (criteria.length <= 200) ? criteria : criteria.substring(0, 200) | ||
| models.sequelize.query(`SELECT * FROM Products WHERE ((name LIKE '%${criteria}%' OR description LIKE '%${criteria}%') AND deletedAt IS NULL) ORDER BY name`) // vuln-code-snippet vuln-line unionSqlInjectionChallenge dbSchemaChallenge | ||
| .then(([products]: any) => { | ||
| const dataString = JSON.stringify(products) | ||
| if (challengeUtils.notSolved(challenges.unionSqlInjectionChallenge)) { // vuln-code-snippet hide-start | ||
| let solved = true | ||
| UserModel.findAll().then(data => { | ||
| const users = utils.queryResultToJson(data) | ||
| if (users.data?.length) { | ||
| for (let i = 0; i < users.data.length; i++) { | ||
| solved = solved && utils.containsOrEscaped(dataString, users.data[i].email) && utils.contains(dataString, users.data[i].password) | ||
| if (!solved) { | ||
| break | ||
| } | ||
| } | ||
| if (solved) { | ||
| challengeUtils.solve(challenges.unionSqlInjectionChallenge) | ||
| } | ||
| } | ||
| }).catch((error: Error) => { | ||
| next(error) | ||
| }) | ||
| } | ||
| if (challengeUtils.notSolved(challenges.dbSchemaChallenge)) { | ||
| let solved = true | ||
| models.sequelize.query('SELECT sql FROM sqlite_master').then(([data]: any) => { | ||
| const tableDefinitions = utils.queryResultToJson(data) | ||
| if (tableDefinitions.data?.length) { | ||
| for (let i = 0; i < tableDefinitions.data.length; i++) { | ||
| if (tableDefinitions.data[i].sql) { | ||
| solved = solved && utils.containsOrEscaped(dataString, tableDefinitions.data[i].sql) | ||
| if (!solved) { | ||
| break | ||
| } | ||
| } | ||
| } | ||
| if (solved) { | ||
| challengeUtils.solve(challenges.dbSchemaChallenge) | ||
| } | ||
| } | ||
| }) | ||
| } // vuln-code-snippet hide-end | ||
| for (let i = 0; i < products.length; i++) { | ||
| products[i].name = req.__(products[i].name) | ||
| products[i].description = req.__(products[i].description) | ||
| } | ||
| res.json(utils.queryResultToJson(products)) | ||
| }).catch((error: ErrorWithParent) => { | ||
| next(error.parent) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // vuln-code-snippet start unionSqlInjectionChallenge dbSchemaChallenge | ||
| module.exports = function searchProducts () { | ||
| return (req: Request, res: Response, next: NextFunction) => { | ||
| let criteria: any = req.query.q === 'undefined' ? '' : req.query.q ?? '' | ||
| criteria = (criteria.length <= 200) ? criteria : criteria.substring(0, 200) | ||
| models.sequelize.query(`SELECT * FROM Products WHERE ((name LIKE :criteria OR description LIKE :criteria) AND deletedAt IS NULL) ORDER BY name`, | ||
| { replacements: { criteria: '%' + criteria + '%' }, type: models.sequelize.QueryTypes.SELECT } // use parameterized query | ||
| ) | ||
| .then(([products]: any) => { | ||
| const dataString = JSON.stringify(products) | ||
| if (challengeUtils.notSolved(challenges.unionSqlInjectionChallenge)) { // vuln-code-snippet hide-start | ||
| let solved = true | ||
| UserModel.findAll().then(data => { | ||
| const users = utils.queryResultToJson(data) | ||
| if (users.data?.length) { | ||
| for (let i = 0; i < users.data.length; i++) { | ||
| solved = solved && utils.containsOrEscaped(dataString, users.data[i].email) && utils.contains(dataString, users.data[i].password) | ||
| if (!solved) { | ||
| break | ||
| } | ||
| } | ||
| if (solved) { | ||
| challengeUtils.solve(challenges.unionSqlInjectionChallenge) | ||
| } | ||
| } | ||
| }).catch((error: Error) => { | ||
| next(error) | ||
| }) | ||
| } | ||
| if (challengeUtils.notSolved(challenges.dbSchemaChallenge)) { | ||
| let solved = true | ||
| models.sequelize.query('SELECT sql FROM sqlite_master').then(([data]: any) => { | ||
| const tableDefinitions = utils.queryResultToJson(data) | ||
| if (tableDefinitions.data?.length) { | ||
| for (let i = 0; i < tableDefinitions.data.length; i++) { | ||
| if (tableDefinitions.data[i].sql) { | ||
| solved = solved && utils.containsOrEscaped(dataString, tableDefinitions.data[i].sql) | ||
| if (!solved) { | ||
| break | ||
| } | ||
| } | ||
| } | ||
| if (solved) { | ||
| challengeUtils.solve(challenges.dbSchemaChallenge) | ||
| } | ||
| } | ||
| }) | ||
| } // vuln-code-snippet hide-end | ||
| for (let i = 0; i < products.length; i++) { | ||
| products[i].name = req.__(products[i].name) | ||
| products[i].description = req.__(products[i].description) | ||
| } | ||
| res.json(utils.queryResultToJson(products)) | ||
| }).catch((error: ErrorWithParent) => { | ||
| next(error.parent) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // vuln-code-snippet start unionSqlInjectionChallenge dbSchemaChallenge | ||
| module.exports = function searchProducts () { | ||
| return (req: Request, res: Response, next: NextFunction) => { | ||
| let criteria: any = req.query.q === 'undefined' ? '' : req.query.q ?? '' | ||
| criteria = (criteria.length <= 200) ? criteria : criteria.substring(0, 200) | ||
| const query = `SELECT * FROM Products WHERE ((name LIKE :criteria OR description LIKE :criteria) AND deletedAt IS NULL) ORDER BY name`; | ||
| const options = { replacements: { criteria: `%${criteria}%` }, type: QueryTypes.SELECT }; | ||
| models.sequelize.query(query, options) | ||
| .then(([products]: any) => { | ||
| const dataString = JSON.stringify(products) | ||
| if (challengeUtils.notSolved(challenges.unionSqlInjectionChallenge)) { // vuln-code-snippet hide-start | ||
| let solved = true | ||
| UserModel.findAll().then(data => { | ||
| const users = utils.queryResultToJson(data) | ||
| if (users.data?.length) { | ||
| for (let i = 0; i < users.data.length; i++) { | ||
| solved = solved && utils.containsOrEscaped(dataString, users.data[i].email) && utils.contains(dataString, users.data[i].password) | ||
| if (!solved) { | ||
| break | ||
| } | ||
| } | ||
| if (solved) { | ||
| challengeUtils.solve(challenges.unionSqlInjectionChallenge) | ||
| } | ||
| } | ||
| }).catch((error: Error) => { | ||
| next(error) | ||
| }) | ||
| } | ||
| if (challengeUtils.notSolved(challenges.dbSchemaChallenge)) { | ||
| let solved = true | ||
| models.sequelize.query('SELECT sql FROM sqlite_master').then(([data]: any) => { | ||
| const tableDefinitions = utils.queryResultToJson(data) | ||
| if (tableDefinitions.data?.length) { | ||
| for (let i = 0; i < tableDefinitions.data.length; i++) { | ||
| if (tableDefinitions.data[i].sql) { | ||
| solved = solved && utils.containsOrEscaped(dataString, tableDefinitions.data[i].sql) | ||
| if (!solved) { | ||
| break | ||
| } | ||
| } | ||
| } | ||
| if (solved) { | ||
| challengeUtils.solve(challenges.dbSchemaChallenge) | ||
| } | ||
| } | ||
| }) | ||
| } // vuln-code-snippet hide-end | ||
| for (let i = 0; i < products.length; i++) { | ||
| products[i].name = req.__(products[i].name) | ||
| products[i].description = req.__(products[i].description) | ||
| } | ||
| res.json(utils.queryResultToJson(products)) | ||
| }).catch((error: ErrorWithParent) => { | ||
| next(error.parent) | ||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||
| password = 'fjdkf7GG@9ikDF5!nZzGz' | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗Cycode: Secret of type: 'Generic Password' was found. DescriptionA generic secret or password is an authentication token used to access a computer or application and is assigned to a password variable. Company Remediation GuidelinePlease see http://www.espn.com for more info Tell us what how you wish to proceed using one of the following commands:
|
||||||
Uh oh!
There was an error while loading. Please reload this page.