Skip to content
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

[Lab] Test after project delete #149

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f3248e7
Added search query + introduced vulnerability
mwillfox Jun 29, 2023
b0ada84
Amplify Security - Code fix for CWE-89 accepted
amplify-local[bot] Jan 2, 2024
4a425aa
Revert "Amplify Security - Code fix for CWE-89 accepted"
mwillfox Jan 2, 2024
1d3a90a
Amplify Security - Code fix for CWE-89 accepted
amplify-local[bot] Jan 3, 2024
f827337
Revert "Amplify Security - Code fix for CWE-89 accepted"
mwillfox Jan 3, 2024
6a67766
Amplify Security - Code fix for CWE-89 accepted
amplify-local[bot] Jan 3, 2024
c457624
Revert "Amplify Security - Code fix for CWE-89 accepted"
mwillfox Jan 3, 2024
6f8b7a8
Amplify Security - Code fix for CWE-89 accepted
amplify-local[bot] Jan 3, 2024
85f1b51
Revert "Amplify Security - Code fix for CWE-89 accepted"
mwillfox Jan 3, 2024
f05622b
Amplify Security - Code fix for CWE-89 accepted
amplify-local[bot] Jan 15, 2024
7fd60f2
Revert "Amplify Security - Code fix for CWE-89 accepted"
mwillfox Jan 15, 2024
772251a
Amplify Security - Code fix for CWE-89 accepted
amplify-local[bot] Mar 14, 2024
8d5643d
Revert "Amplify Security - Code fix for CWE-89 accepted"
mwillfox Mar 14, 2024
a814a3f
Ignored CWE-89 vuln
mwillfox Mar 28, 2024
253044a
Removed CWE-89 ignore comment
mwillfox Mar 28, 2024
9037f1a
Ignored SQL injection
mwillfox Apr 2, 2024
218b184
Removed ignore on vulnerable SQL injection
mwillfox Apr 2, 2024
b47abed
Updated Gruntfile.js
mwillfox Apr 25, 2024
f1b856f
Added .amplifyignore
mwillfox May 9, 2024
0cff134
updated .amplifyignore
mwillfox May 9, 2024
41c57bb
ignoring SQL injection
mwillfox May 23, 2024
8b20ccb
removing vuln ignore
mwillfox May 23, 2024
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
1 change: 1 addition & 0 deletions .amplifyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
routes/*.js
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-compress')
grunt.registerTask('package', ['replace_json:manifest', 'compress:pckg', 'checksum'])
}

// Gruntfile.js
60 changes: 59 additions & 1 deletion routes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,72 @@
* Copyright (c) 2014-2023 Bjoern Kimminich & the OWASP Juice Shop contributors.
* SPDX-License-Identifier: MIT
*/
import models = require('../models/index')
import { Request, Response, 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)
console.log(criteria)
models.sequelize.query(`SELECT * FROM Products WHERE ((name LIKE '%${criteria}%' OR description LIKE '%${criteria}%') AND deletedAt IS NULL) ORDER BY name`)
.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 end unionSqlInjectionChallenge dbSchemaChallenge
Loading