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

remove ip address from logs #65

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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 = async (route, sessionID, ipAddress) => {
const logPageView = async (route, sessionID) => {
logger.info({
type: 'PageView',
pageRoute: route,
message: `page view occurred for page: ${route}`,
sessionId: await hash(sessionID),
ipAddress: await hash(ipAddress)
sessionId: await 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