-
Notifications
You must be signed in to change notification settings - Fork 14
Add audit logging for sec events #410
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
99da2ad
feat: rejection events
ansgarlichter d383bb0
Merge branch 'main' into feat/emit-events-for-security-relevant-rejec…
ansgarlichter c47b7d1
feat: add acceptable media types to AttachmentUploadRejected event
ansgarlichter 823a3e5
refactor: await event
ansgarlichter fae766f
refactor: await event
ansgarlichter 94e633b
refactor: await event
ansgarlichter 8f6dbe6
fix: emit events inside cds.spawn to get consumers possibility to rea…
ansgarlichter 698a554
Merge branch 'feat/emit-events-for-security-relevant-rejections' of g…
ansgarlichter e8f3872
fix: linting
ansgarlichter 836c337
Merge branch 'main' into feat/emit-events-for-security-relevant-rejec…
KoblerS 0dcbfd6
Adding audit-logging for sec events
schiwekM d50c7be
Formatting
schiwekM b3095ea
Update basic.js
schiwekM 9e6f796
Update basic.js
schiwekM f7a02c1
Create auditLogging.test.js
schiwekM 8f918ad
Cleanup
schiwekM 38b48d0
Formatting
schiwekM 22c31d6
Merge branch 'main' into add-audit-logging-for-sec-events
schiwekM f1f104b
Update testUtils.js
schiwekM a9b055c
Increase outbox processing power
schiwekM 01645d8
Formatting
schiwekM 4a2a9e7
Merge branch 'main' into add-audit-logging-for-sec-events
schiwekM 996cb8a
Fix merge change
schiwekM 5ff0f84
Formatting
schiwekM 1ba10c0
Update CHANGELOG.md
schiwekM c2ff61e
Update CHANGELOG.md
schiwekM 800e0ec
Update CHANGELOG.md
schiwekM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| require("../../lib/csn-runtime-extension") | ||
| const cds = require("@sap/cds") | ||
| cds.env.requires["audit-log"] = { | ||
| impl: "@cap-js/audit-logging/srv/log2console", | ||
| outbox: false, | ||
| } | ||
| const { join } = cds.utils.path | ||
| const app = join(__dirname, "../incidents-app") | ||
| cds.test(app) | ||
|
|
||
| let attachmentsSvc | ||
|
|
||
| beforeEach(async () => { | ||
| const svc = await cds.connect.to("attachments") | ||
| attachmentsSvc = cds.unboxed(svc) | ||
| }) | ||
|
|
||
| describe("Audit logging for security events (audit-logging dependency present)", () => { | ||
| const log = cds.test.log() | ||
|
|
||
| it("should log AttachmentDownloadRejected as SecurityEvent", async () => { | ||
| await attachmentsSvc.emit("AttachmentDownloadRejected", { | ||
| target: "AdminService.Incidents.attachments", | ||
| keys: { ID: "att-001" }, | ||
| status: "Infected", | ||
| ipAddress: "10.0.0.1", | ||
| }) | ||
|
|
||
| expect(log.output).toContain("[audit-log] - SecurityEvent:") | ||
| expect(log.output).toContain("AttachmentDownloadRejected") | ||
| expect(log.output).toContain("Infected") | ||
| }) | ||
|
|
||
| it("should log AttachmentSizeExceeded as SecurityEvent", async () => { | ||
| await attachmentsSvc.emit("AttachmentSizeExceeded", { | ||
| target: "AdminService.Incidents.attachments", | ||
| keys: { ID: "att-002" }, | ||
| filename: "large-file.pdf", | ||
| fileSize: 999999999, | ||
| maxFileSize: 5242880, | ||
| ipAddress: "192.168.1.10", | ||
| }) | ||
|
|
||
| expect(log.output).toContain("[audit-log] - SecurityEvent:") | ||
| expect(log.output).toContain("AttachmentSizeExceeded") | ||
| expect(log.output).toContain("large-file.pdf") | ||
| expect(log.output).toContain("999999999") | ||
| expect(log.output).toContain("5242880") | ||
| }) | ||
|
|
||
| it("should log AttachmentUploadRejected as SecurityEvent", async () => { | ||
| await attachmentsSvc.emit("AttachmentUploadRejected", { | ||
| target: "AdminService.Incidents.attachments", | ||
| keys: { ID: "att-003" }, | ||
| filename: "script.exe", | ||
| mimeType: "application/x-msdownload", | ||
| acceptableMediaTypes: ["image/jpeg", "image/png"], | ||
| reason: | ||
| "MIME type 'application/x-msdownload' is not in @Core.AcceptableMediaTypes", | ||
| ipAddress: "172.16.0.5", | ||
| }) | ||
|
|
||
| expect(log.output).toContain("[audit-log] - SecurityEvent:") | ||
| expect(log.output).toContain("AttachmentUploadRejected") | ||
| expect(log.output).toContain("script.exe") | ||
| expect(log.output).toContain("application/x-msdownload") | ||
| }) | ||
| }) | ||
|
|
||
| describe("Audit logging when audit-logging is disabled", () => { | ||
| const log = cds.test.log() | ||
|
|
||
| it("should not register audit log handlers when hasAuditLogging returns false", async () => { | ||
| // Override hasAuditLogging to return false | ||
| const originalLog = cds.env.requires["audit-log"] | ||
| cds.env.requires["audit-log"] = false | ||
|
|
||
| // Create a fresh AttachmentsService instance with audit logging disabled | ||
| const AttachmentsService = require("../../srv/basic") | ||
| const svc = new AttachmentsService() | ||
| svc.model = cds.model | ||
| // Stub super.init() to avoid full service bootstrap | ||
| const origInit = Object.getPrototypeOf(AttachmentsService.prototype).init | ||
| Object.getPrototypeOf(AttachmentsService.prototype).init = jest | ||
| .fn() | ||
| .mockResolvedValue(undefined) | ||
|
|
||
| await svc.init() | ||
|
|
||
| // Restore super.init | ||
| Object.getPrototypeOf(AttachmentsService.prototype).init = origInit | ||
|
|
||
| // The service should have handlers for DeleteAttachment and DeleteInfectedAttachment | ||
| // but NOT for the security events routed to audit logging | ||
| const registeredEvents = (svc._handlers?.on || []).map((h) => | ||
| Array.isArray(h.for) ? h.for : [h.for], | ||
| ) | ||
| const flatEvents = registeredEvents.flat().filter(Boolean) | ||
|
|
||
| expect(flatEvents).not.toContain("AttachmentDownloadRejected") | ||
| expect(flatEvents).not.toContain("AttachmentSizeExceeded") | ||
| expect(flatEvents).not.toContain("AttachmentUploadRejected") | ||
|
|
||
| // Verify no audit log output was produced | ||
| expect(log.output).not.toContain("[audit-log] - SecurityEvent:") | ||
| cds.env.requires["audit-log"] = originalLog | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.