Skip to content

Box: fix Abnormal user activity rule that could never alert - #15764

Open
Rafi (Muhammad-Rafiullah) wants to merge 3 commits into
Azure:masterfrom
Muhammad-Rafiullah:fix/box-abnormal-user-activity
Open

Rafi (Muhammad-Rafiullah) wants to merge 3 commits into
Azure:masterfrom
Muhammad-Rafiullah:fix/box-abnormal-user-activity

Conversation

@Muhammad-Rafiullah

@Muhammad-Rafiullah Rafi (Muhammad-Rafiullah) commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Change(s):

  • Rewrote the query in Solutions/Box/Analytic Rules/BoxAbnormalUserActivity.yaml (rule id 1139230c-cf10-45db-b616-fed0d1415c05).
  • The new query counts each user's events per hour over the 14 day query period. The newest hour is the current activity and the earlier hours in which the user was active are the baseline. It alerts when the last hour has at least 50 events and is more than three standard deviations above the user's own hourly average.
  • Users are keyed on SrcUserUpn instead of the display name, and that value is what goes into AccountCustomEntity. The entity mapping itself is unchanged.
  • Updated the description to say what the rule does and fixed the "avarage" typo in it.
  • queryFrequency, queryPeriod, tactics, techniques and connectors are unchanged.
  • After review: BaselineStdev is set to 0 explicitly when the user has fewer than two earlier active hours.
  • Solution version 3.1.7 -> 3.1.8, a row in Solutions/Box/ReleaseNotes.md, and the package rebuilt with Tools/Create-Azure-Sentinel-Solution/V3/createSolutionV3.ps1 (mainTemplate.json, createUiDefinition.json, 3.1.8.zip).
  • After the second review: added a table description and descriptions for all 42 columns of BoxEventsV2_CL in Solutions/Box/Data Connectors/BoxEvents_ccp/BoxEvents_table.json (VAL-TBL-01/02), rebuilt the package so mainTemplate.json carries the same text (VAL-TBL-03), and fixed the "Abmormal" typo in the rule name and the ReleaseNotes row.

Reason for Change(s):

  • Fixes Box 'Abnormal user activity' rule (1139230c) can never raise an alert #15664
  • The old query could not return rows on any data:
    • the baseline counted rows after a union (1 or 2 per user) instead of adding up events, then divided by 29 with integers, so EventsPerDay was always 0
    • the two "last hour" parts had no time filter and grouped by SourceName, which is the file or folder, not the user
    • join ... on k with a constant key uses the default join kind, which kept one row from the left side
    • the final filter was EventsPerDay > TotalEventsH, which is the wrong way round for a spike and can never be true when the left side is 0
  • The fix follows the approach suggested in the issue. I changed it to read BoxEvents once instead of twice and to line the hourly buckets up with the run time, so every baseline hour is a full hour.

Version Updated:

  • Yes. Rule version 1.0.1 -> 1.0.2, solution version 3.1.7 -> 3.1.8.

Testing Completed:

  • Yes, with synthetic data only. I do not have a workspace with real Box data.
  • Ran the old and the new query in a Log Analytics workspace with BoxEvents replaced by generated rows (let BoxEvents = union (range ...)). 19 cases, including:
    • the repro snippet from the issue: old query returns nothing, new query returns the user
    • steady 20 events an hour, then 500 in the last hour: alert
    • steady 60 events an hour with no spike: no alert
    • a user whose hourly count swings between 40 and 200: no alert at 150, alert at 1000
    • two users spiking at the same time next to a steady third user: both returned, the third is not
    • a new user with no history: alert at 500 events, no alert at 10
    • a spike two hours ago with a normal last hour: no alert
    • events with an empty SrcUserUpn: ignored
    • 49 events in the last hour: no alert, 50: alert
  • The old query returned no rows in all 19 cases.
  • After the stdev change I re-ran a smaller set (a new user at 60 events and at 10, a user with one earlier active hour, steady and spiking users). Same results as before the change.
  • Also ran the new query through the solution's BoxEvents parser on a generated BoxEventsV2_CL table with the columns from BoxEvents_table.json. It returned the two expected users.
  • Not tested: real Box events, the legacy BoxEvents_CL table, and the rule running on a schedule in Sentinel. The 50 event floor and the three standard deviation threshold are a starting point and may need tuning on real traffic. Expect alerts for legitimate bulk activity such as a first Box Drive sync, migrations, service accounts and new users with no history.

Checked that the validations are passing and have addressed any issues that are present:

  • Yes, locally, with PRNUM set to this PR:
    • .script/tests/KqlvalidationsTests: 13/13 passed, including Validate_DetectionQueries_HaveValidKql for BoxAbnormalUserActivity.yaml
    • .script/tests/detectionTemplateSchemaValidation: 6/6 passed (run on the .NET 8 runtime, since the project targets .NET Core 3.1)
    • Both re-run after the table description change, same results.
  • DataConnectorValidations and SolutionValidations failed on the previous commit with VAL-TBL-01/02/03 for BoxEventsV2_CL. I ran the check behind them (.script/utils/dataConnectorCheckers/customTableSchemaChecker.ts from master) locally with Node against the Box connector files and the package: it passes now. Against the previous package it reports the same errors as CI. I have not run the full CI jobs.
  • The packaging tool's ARM-TTK step reports one failure, "IDs Should Be Derived From ResourceIDs". The current 3.1.7 package fails it the same way (49 passed, 1 failed, 26 exempted in both), so it is not from this change.

Note on the package diff: the packaging tool reads rule YAML into unordered hashtables, so on each run it shuffles key order inside requiredDataConnectors and entityMappings for every rule. Apart from that reordering, the template changes are the version numbers, this rule's name, description and query, the BoxEventsV2_CL table and column descriptions, and one workbook metadata description that the 3.1.7 package had as a stringified PowerShell object.

The query could not return rows. The baseline counted rows after a union instead of adding up events, then divided by 29 with integers, so the daily average was always 0. The "last hour" parts had no time filter and grouped by SourceName (the file) instead of the user, the join on a constant key kept a single user, and the comparison pointed the wrong way.

The new query counts each user's events per hour over 14 days, takes the newest hour as the current activity and the earlier active hours as the baseline, and alerts when the last hour has at least 50 events and is more than three standard deviations above the user's own average. Users are keyed on SrcUserUpn instead of the display name.

Description updated to match and rule version bumped to 1.0.2.

Fixes Azure#15664
@github-actions github-actions Bot added 1P Solution 1P Microsoft-owned Sentinel solution Solution Solution specialty review needed labels Nov 28, 2026
@v-skharode

Copy link
Copy Markdown
Contributor

Hi Rafi (@Muhammad-Rafiullah)
Thanks for fixing the query logic and providing detailed synthetic testing results.

I have a few points to clarify before approval:

  • For users without historical activity, BaselineAvg is set to zero, but BaselineStdev may remain null. Please ensure the detection handles this case explicitly.
  • Please confirm that calculating the baseline using only active hours is intentional.
  • Please confirm whether the solution package and release notes require updates for this rule version change.

Once these points are addressed, we can proceed with the review.

Users with fewer than two earlier active hours now get a baseline stdev
of 0 set in the query, instead of relying on what stdevif returns for an
empty group. Results are the same as before.

Bump the solution to 3.1.8, add a ReleaseNotes row and rebuild the
package with the V3 packaging tool.
@Muhammad-Rafiullah

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look.

  • Stdev for new users: stdevif over no rows actually comes back as 0, not null (it's avgif that gives NaN, which the query already handled). I've made it explicit anyway, so anyone with fewer than two earlier active hours gets a stdev of 0. Re-ran it: a new user with 60 events in the hour alerts, a new user with 10 doesn't, and the other cases are unchanged.
  • Active hours only: yes, on purpose. If idle hours count as zero, the average for someone who only uses Box now and then ends up close to zero, so any normal session over 50 events would alert. Comparing to their usual active hour avoids that.
  • Package and release notes: yes. I've bumped the solution to 3.1.8, added a ReleaseNotes row and rebuilt the package with the V3 tool. Details are in the PR description.

@v-skharode

Copy link
Copy Markdown
Contributor

Hi Rafi (@Muhammad-Rafiullah)
Thanks for the fixes. Please also fix the remaining validation failures:

  • Add a table description and descriptions for all columns in BoxEventsV2_CL (VAL-TBL-01/02).
  • Apply the same descriptions to the packaged table in mainTemplate.json.
  • Correct the typo “Abmormal” to “Abnormal” in the rule name and release notes.
  • Then rerun both failing CI checks and push a new commit.

Add a table description and a description for each of the 42 columns
in BoxEvents_table.json, as required by the custom table schema check
(VAL-TBL-01/02), and rebuild the 3.1.8 package so mainTemplate.json
carries the same text (VAL-TBL-03).

Fix "Abmormal" to "Abnormal" in the rule name and the ReleaseNotes row.
@Muhammad-Rafiullah

Copy link
Copy Markdown
Contributor Author

Thanks. Pushed a new commit with these:

  • Added a table description and descriptions for all 42 columns of BoxEventsV2_CL in Data Connectors/BoxEvents_ccp/BoxEvents_table.json. Each column description is based on the Box Events API field the DCR builds it from, for example source_owned_by_login comes from source.owned_by.login.
  • Rebuilt the 3.1.8 package with the V3 packaging tool, so the packaged table in mainTemplate.json has the same descriptions. The package was not edited by hand.
  • Fixed "Abmormal" to "Abnormal" in the rule name and the release notes row. The package picks up the new name too.

I ran the custom table check from master (customTableSchemaChecker.ts) locally against the Box files and it passes now. Against the previous package it gives the same VAL-TBL errors CI reported. Both checks should rerun on the new commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1P Solution 1P Microsoft-owned Sentinel solution Solution Solution specialty review needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Box 'Abnormal user activity' rule (1139230c) can never raise an alert

2 participants