Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Unreleased

### Fixed

- Security audit events (`AttachmentSizeExceeded`, `AttachmentUploadRejected`, `AttachmentDownloadRejected`) now log the real client IP on reverse-proxy deployments (e.g. BTP Cloud Foundry) by reading `X-Forwarded-For` with fallback to `socket.remoteAddress`.

## Version 3.11.0

### Added
Expand Down
10 changes: 7 additions & 3 deletions lib/generic-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ async function validateAttachment(req) {

if (scanEnabled) {
if (status !== "Clean") {
const ipAddress = req.req?.socket?.remoteAddress
const ipAddress =
req.req?.headers?.["x-forwarded-for"] ||
req.req?.socket?.remoteAddress
cds.spawn(async () => {
try {
const srv = await cds.connect.to("attachments")
Expand Down Expand Up @@ -272,7 +274,8 @@ async function validateAttachmentSize(req, validateContentLength = false) {
const attachmentRef = await SELECT.one("filename")
.from(req.target)
.where({ up__ID: req.data.up__ID })
const ipAddress = req.req?.socket?.remoteAddress
const ipAddress =
req.req?.headers?.["x-forwarded-for"] || req.req?.socket?.remoteAddress
Comment on lines +277 to +278
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const ipAddress =
req.req?.headers?.["x-forwarded-for"] || req.req?.socket?.remoteAddress
const {ipAddress = req.req.ip

cds.spawn(async () => {
try {
const AttachmentsSrv = await cds.connect.to("attachments")
Expand Down Expand Up @@ -330,7 +333,8 @@ function validateAttachmentMimeType(req) {
const acceptableMediaTypes =
req.target.elements.content["@Core.AcceptableMediaTypes"] || "*/*"
if (!checkMimeTypeMatch(acceptableMediaTypes, mimeType)) {
const ipAddress = req.req?.socket?.remoteAddress
const ipAddress =
req.req?.headers?.["x-forwarded-for"] || req.req?.socket?.remoteAddress
Comment on lines +336 to +337
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const ipAddress =
req.req?.headers?.["x-forwarded-for"] || req.req?.socket?.remoteAddress
const {ipAddress = req.req.ip

cds.spawn(async () => {
try {
const AttachmentsSrv = await cds.connect.to("attachments")
Expand Down