Skip to content

Commit

Permalink
PP-12235 Fix loop bound injection
Browse files Browse the repository at this point in the history
Code QL flagges this as potential loop bound injection.
Use ES6 functionality to replace use of lodash.
  • Loading branch information
stephencdaly committed Mar 5, 2024
1 parent 1b8fccd commit 42ce047
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/controllers/payment-types/post-index.controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const lodash = require('lodash')

const paths = require('../../paths')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')
const { ConnectorClient } = require('../../services/clients/connector.client')
Expand All @@ -10,8 +8,8 @@ const connector = new ConnectorClient(process.env.CONNECTOR_URL)
module.exports = async function updateCardTypes (req, res, next) {
const accountId = req.account.gateway_account_id

const acceptedDebitCards = typeof req.body.debit === 'string' ? [req.body.debit] : req.body.debit
const acceptedCreditCards = typeof req.body.credit === 'string' ? [req.body.credit] : req.body.credit
const acceptedDebitCards = (typeof req.body.debit === 'string' ? [req.body.debit] : req.body.debit) || []
const acceptedCreditCards = (typeof req.body.credit === 'string' ? [req.body.credit] : req.body.credit) || []

if (typeof acceptedDebitCards === 'undefined' && typeof acceptedCreditCards === 'undefined') {
req.flash('genericError', 'You must choose at least one card')
Expand All @@ -21,7 +19,7 @@ module.exports = async function updateCardTypes (req, res, next) {
}

const payload = {
card_types: lodash.union(acceptedDebitCards, acceptedCreditCards)
card_types: [...new Set([...acceptedDebitCards, ...acceptedCreditCards])]
}

try {
Expand Down

0 comments on commit 42ce047

Please sign in to comment.