cli-microsoft365 icon indicating copy to clipboard operation
cli-microsoft365 copied to clipboard

New command: purview threatassessment add

Open nicodecleyre opened this issue 3 years ago • 23 comments

Usage

m365 purview threatassessment add

Description

Create a threat assessment

Options

Option Description
-t, --type <type> The type of threat assessment to retrieve. Supports mail, file, emailFile and url.
-e, --expectedAssessment <expectedAssessment> The expected assessment from submitter. Possible values are: block and unblock.
-c, --category <category> The threat category. Possible values are: spam, phishing, malware.
-r, --recipientEmail [recipientEmail] The mail recipient whose policies are used to assess the mail. Can only be used for threat assessment with type mail and emailFile.
-p, --path [path] Local path to the file to upload. Can only be used for threat assessment with type file and emailFile.
-u, --url [url] The URL string. Can only be used for threat assessment with type url.
-m, --messageUri [messageUri] The resource URI of the mail message for assessment. Can only be used for threat assessment with type mail.

Examples

Create a mail threat assessment

m365 purview threatassessment add --type mail --expectedAssessment block --recipientEmail "[email protected]" --category spam --messageUri "https://graph.microsoft.com/v1.0/users/c52ce8db-3e4b-4181-93c4-7d6b6bffaf60/messages/AAMkADU3MWUxOTU0LWNlOTEt="

Create a emailFile threat assessment

m365 purview threatassessment add --type emailFile --expectedAssessment block --category malware --recipientEmail "[email protected]" --contentData "UmVjZWl2ZWQ6IGZyb20gTVcyUFIwME1CMDMxNC5uYW1wcmQwMC"

Create a file threat assessment

m365 purview threatassessment add --type file --expectedAssessment block --category malware --fileName "test.txt" --contentData "VGhpcyBpcyBhIHRlc3QgZmlsZQ=="

Create a url threat assessment

m365 purview threatassessment add --type url --expectedAssessment block --category phishing --url "http://contoso.com"

Default properties

No response

Additional Info

API request: https://learn.microsoft.com/en-us/graph/api/informationprotection-post-threatassessmentrequests?view=graph-rest-1.0&tabs=http

Needed permissions

  • ThreatAssessment.ReadWrite.All

nicodecleyre avatar Jan 28 '23 10:01 nicodecleyre

Hi @nicodecleyre, A few comments:

  • I think url and messageUri should be optional, if I read the descriptions correctly.
  • could you also add some shorts for the options?
  • I think we should reference the necessary permission level as well.

Should we maybe add a short More information section with a link to more information about threat assessments?

martinlingstuyl avatar Jan 28 '23 16:01 martinlingstuyl

Also: as we've got some conditionally required options, could you add that in a remarks section so it's clear for the contributor that will build this how to treat option validation?

martinlingstuyl avatar Jan 28 '23 16:01 martinlingstuyl

  • i'm sorry, it seems that i made the optional options required and visa versa. Updated the specs with the right notation
  • added some short. But I'm not sure which to define for category & contentData since they both start with the same letter?
  • updated the specs with the needed permissions

nicodecleyre avatar Jan 29 '23 09:01 nicodecleyre

Hi @nicodecleyre , about contentData, we could also just name it content and let people pipe in a filepath, just like we do elsewhere.

martinlingstuyl avatar Feb 10 '23 21:02 martinlingstuyl

About the shorts: just pick the one that's most important and add -c for that. The other one will not have a short.

martinlingstuyl avatar Feb 10 '23 21:02 martinlingstuyl

Thanks @martinlingstuyl , updated the specs

nicodecleyre avatar Feb 10 '23 22:02 nicodecleyre

Slept on it @nicodecleyre : Let's rename --content to path:

-p, --path [path] Local path to the file to upload

Also, we can now remove the filename option, as we can get that from the file.

martinlingstuyl avatar Feb 11 '23 06:02 martinlingstuyl

Slept on it @nicodecleyre : Let's rename --content to path:

-p, --path [path] Local path to the file to upload

Also, we can now remove the filename option, as we can get that from the file.

Updated

nicodecleyre avatar Feb 11 '23 07:02 nicodecleyre

Pick me!

MathijsVerbeeck avatar Feb 11 '23 21:02 MathijsVerbeeck

All yours @MathijsVerbeeck!

milanholemans avatar Feb 11 '23 21:02 milanholemans

Just a quick feedback: I'm currently working on this issue, but am having quite a few API issues: Sometimes, I will get this error: image

Another time, the API throttles, while I'm not doing anything on the tenant: image

And sometimes, it just succeeds, even though the response is very slow (more than 5 seconds atleast).

Not sure what to think about this. When running it in the Graph Explorer. Same thing occurs.

MathijsVerbeeck avatar Feb 13 '23 21:02 MathijsVerbeeck

Hi @MathijsVerbeeck, thanks for the feedback! I will pass this on to Microsoft using the MVP channels. I did the same for the retention endpoints. 👍

martinlingstuyl avatar Feb 13 '23 22:02 martinlingstuyl

Perfect. I'll await your feedback before continuing 😁

MathijsVerbeeck avatar Feb 13 '23 22:02 MathijsVerbeeck

Oh no, just continue the work. They'll have to look at it, and it might take some time for them to fix it. It's beta after all.

martinlingstuyl avatar Feb 13 '23 22:02 martinlingstuyl

Oh no, just continue the work. They'll have to look at it, and it might take some time for them to fix it. It's beta after all.

The command is finished, but I can't really test it properly with the API not working well 😄. It is also in the V1.0 endpoint already, but I tested both V1.0 and beta but both aren't working properly.

MathijsVerbeeck avatar Feb 14 '23 09:02 MathijsVerbeeck

Still having the throttling / timeout issues as soon as I've added one threat assessment, just letting you know 😄.

MathijsVerbeeck avatar Feb 25 '23 00:02 MathijsVerbeeck

@martinlingstuyl Not sure whats going on, but when retesting the endpoint, I now get the following error, both in Graph Explorer & using the Cli

image

As you can see, I granted the ThreatAssessment.ReadWrite.All, and validated the bearer token and it exists there, so not sure what's going wrong.

MathijsVerbeeck avatar Mar 14 '23 11:03 MathijsVerbeeck

Yes, I've seen this too. I've let MS know last week. No response yet :)

martinlingstuyl avatar Mar 14 '23 11:03 martinlingstuyl

Yes, I've seen this too. I've let MS know last week. No response yet :)

Unlucky, let's wait for their answer then and I'll put this on hold and recheck in like a week or so 😄. Quite weird as this is in the v1.0 endpoint...

MathijsVerbeeck avatar Mar 14 '23 11:03 MathijsVerbeeck

@martinlingstuyl Still seems to be broken... 😞 Same error although bearer token contains the permission scope...

MathijsVerbeeck avatar Apr 23 '23 12:04 MathijsVerbeeck

Yeah, all these endpoints still fail. I've pointed it out using my channels to MS people, but it hasn't had any effect till now 😁 I'll report it again.

martinlingstuyl avatar Apr 23 '23 12:04 martinlingstuyl

@martinlingstuyl I have noticed that in the meantime, the url and the file threat assessment requests have started working, however, when creating a mail request, it gives the error :

Error: BadRequest - Cannot process the request because it is malformed or incorrect.

Should I continue and already implement the url and file threat assessment request? Or should we wait until everything is working properly?

MathijsVerbeeck avatar Feb 11 '24 14:02 MathijsVerbeeck

2 out of 3 is good enough for me, let's get it in! @MathijsVerbeeck, great to have you back! 💪

martinlingstuyl avatar Feb 11 '24 23:02 martinlingstuyl