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

Completed assigment submission #106

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions frontend/src/app/search-result/search-result.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class SearchResultComponent implements OnDestroy, AfterViewInit {

// vuln-code-snippet start localXssChallenge xssBonusChallenge
filterTable () {
console.log('In filterTable()')
let queryParam: string = this.route.snapshot.queryParams.q
if (queryParam) {
queryParam = queryParam.trim()
Expand Down
22 changes: 11 additions & 11 deletions models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ import { WalletModelInit } from './wallet'

const Sequelize = require('sequelize')

const sequelize = new Sequelize('database', 'username', 'password', {
dialect: 'sqlite',
retry: {
match: [/SQLITE_BUSY/],
name: 'query',
max: 5
},
transactionType: 'IMMEDIATE',
storage: 'data/juiceshop.sqlite',
logging: false
})
const sequelize = new Sequelize('database', 'username', 'password', {
dialect: 'sqlite',
retry: {
match: [/SQLITE_BUSY/],
name: 'query',
max: 5
},
transactionType: 'IMMEDIATE',
storage: 'data/juiceshop.sqlite',
logging: false
})
AddressModelInit(sequelize)
BasketModelInit(sequelize)
BasketItemModelInit(sequelize)
Expand Down
1 change: 1 addition & 0 deletions routes/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const utils = require('../lib/utils')
module.exports = function serveAngularClient () {
return ({ url }: Request, res: Response, next: NextFunction) => {
if (!utils.startsWith(url, '/api') && !utils.startsWith(url, '/rest')) {
console.log('URL SENT IN FIRST IF: ' + url)
res.sendFile(path.resolve('frontend/dist/frontend/index.html'))
} else {
next(new Error('Unexpected path: ' + url))
Expand Down
13 changes: 12 additions & 1 deletion routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ module.exports = function login () {

return (req: Request, res: Response, next: NextFunction) => {
verifyPreLoginChallenges(req) // vuln-code-snippet hide-line
models.sequelize.query(`SELECT * FROM Users WHERE email = '${req.body.email || ''}' AND password = '${security.hash(req.body.password || '')}' AND deletedAt IS NULL`, { model: UserModel, plain: true }) // vuln-code-snippet vuln-line loginAdminChallenge loginBenderChallenge loginJimChallenge
models.sequelize.query(`SELECT * FROM Users WHERE email = '${req.body.email || ''}' AND password = '${security.hash(req.body.password || '')}' AND deletedAt IS NULL`, { model: UserModel, plain: true })
models.sequelize.query(
'SELECT * FROM Users WHERE email = :email AND password = :password AND deletedAt IS NULL',
{
replacements: {
email: req.body.email || '',
password: security.hash(req.body.password || '')
},
model: UserModel,
plain: true
}
) // vuln-code-snippet vuln-line loginAdminChallenge loginBenderChallenge loginJimChallenge
.then((authenticatedUser: { data: User }) => { // vuln-code-snippet neutral-line loginAdminChallenge loginBenderChallenge loginJimChallenge
const user = utils.queryResultToJson(authenticatedUser)
if (user.data?.id && user.data.totpSecret !== '') {
Expand Down
8 changes: 7 additions & 1 deletion routes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import models = require('../models/index')
import { Request, Response, NextFunction } from 'express'
import { UserModel } from '../models/user'
import { QueryTypes } from 'sequelize'

const utils = require('../lib/utils')
const challengeUtils = require('../lib/challengeUtils')
Expand All @@ -20,7 +21,12 @@ 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
const query = 'SELECT * FROM Products WHERE ((name LIKE ? OR description LIKE ?) AND deletedAt IS NULL) ORDER BY name'
models.sequelize.query(query, {
replacements: [`%${criteria}%`, `%${criteria}%`],
type: QueryTypes.SELECT,
logging: (query: any) => console.log(`SQL Query: ${query}`)
})
.then(([products]: any) => {
const dataString = JSON.stringify(products)
if (challengeUtils.notSolved(challenges.unionSqlInjectionChallenge)) { // vuln-code-snippet hide-start
Expand Down