Skip to content

Commit

Permalink
Merge pull request #65 from digital-land/removeIPFromLogs
Browse files Browse the repository at this point in the history
remove ip address from logs
  • Loading branch information
GeorgeGoodall authored Feb 27, 2024
2 parents 9ca1578 + a98dc27 commit dcfbdf1
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ app.use(async (req, res, next) => {
method: req.method,
endpoint: req.originalUrl,
message: `${req.method} request made to ${req.originalUrl}`,
sessionId: await hash(req.sessionID),
ipAddress: await hash(req.ip)
sessionId: await hash(req.sessionID)
})
next()
})
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/uploadController.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ class UploadController extends PageController {
}
}

constructBaseFormData ({ dataset, dataSubject, geomType, organisation, sessionId, ipAddress }) {
constructBaseFormData ({ dataset, dataSubject, geomType, organisation, sessionId }) {
const formData = new FormData()
formData.append('dataset', dataset)
formData.append('collection', dataSubject)
formData.append('organisation', organisation)
formData.append('sessionId', sessionId)
formData.append('ipAddress', ipAddress)

if (geomType) { formData.append('geom_type', geomType) }

Expand All @@ -99,8 +98,7 @@ class UploadController extends PageController {
dataset: req.sessionModel.get('dataset'),
dataSubject: req.sessionModel.get('data-subject'),
geomType: req.sessionModel.get('geomType'),
sessionId: req.session.id,
ipAddress: req.ip
sessionId: req.session.id
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/uploadFileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class UploadFileController extends UploadController {
}

async apiValidateFile (datafile) {
const { filePath, fileName, dataset, dataSubject, organisation, sessionId, ipAddress } = datafile
const { filePath, fileName, dataset, dataSubject, organisation, sessionId } = datafile

const formData = this.constructBaseFormData({ dataset, dataSubject, organisation, sessionId, ipAddress })
const formData = this.constructBaseFormData({ dataset, dataSubject, organisation, sessionId })
const file = new Blob([await fs.readFile(filePath)], { type: lookup(filePath) })
formData.append('upload_file', file, fileName)

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/uploadUrlController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class UploadUrlController extends UploadController {
super.post(req, res, next)
}

async apiValidateUrl (url, { dataset, dataSubject, geomType, organisation, sessionId, ipAddress }) {
const formData = this.constructBaseFormData({ dataset, dataSubject, geomType, organisation, sessionId, ipAddress })
async apiValidateUrl (url, { dataset, dataSubject, geomType, organisation, sessionId }) {
const formData = this.constructBaseFormData({ dataset, dataSubject, geomType, organisation, sessionId })
formData.append('upload_url', url)

const result = await axios.post(this.apiRoute, formData, { timeout: config.api.requestTimeout })
Expand Down
5 changes: 2 additions & 3 deletions src/utils/logging.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import logger from '../utils/logger.js'
import hash from '../utils/hasher.js'

const logPageView = (route, sessionID, ipAddress) => {
const logPageView = (route, sessionID) => {
logger.info({
type: 'PageView',
pageRoute: route,
message: `page view occurred for page: ${route}`,
sessionId: hash(sessionID),
ipAddress: hash(ipAddress)
sessionId: hash(sessionID)
})
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/PageController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('PageController', () => {
expect(callArgs.pageRoute).toEqual('/dataset')
expect(callArgs.message).toEqual('page view occurred for page: /dataset')
expect(callArgs.sessionId).toEqual(await hash('123'))
expect(callArgs.ipAddress).toEqual(await hash('1234'))
expect(callArgs.ipAddress).toBeUndefined()
expect(callArgs.level).toEqual('info')
expect(callArgs.service).toEqual('lpa-data-validation-frontend')
})
Expand Down
1 change: 0 additions & 1 deletion test/unit/uploadFileController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ describe('UploadFileController', () => {
dataset: 'test',
dataSubject: 'test',
geomType: 'test',
ipAddress: 'fakeIp',
sessionId: 'sessionId'
})
expect(req.body.validationResult).toEqual(mockApiValue)
Expand Down

0 comments on commit dcfbdf1

Please sign in to comment.