# Inspect\_message for Motoko

**URL:** <https://forum.dfinity.org/t/inspect-message-for-motoko/10430>\
**Category:** Language Support\
**Tags:** Motoko\
**Created:** [January 22, 2022, 4:21pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430 "2022-01-22T16:21:39Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [January 22, 2022, 4:21pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/1 "2022-01-22T16:21:39Z")

</div>

Is the _inspect\_message_ function planned for Motoko in the near future?

Also, will inspecting and discarding an ingress message with a large payload prevent the canister from being charged cycles, other than the cost of cycles for the _inspect\_message_ function itself?

Lastly, even if Motoko gets _inspect\_message_, how can a canister defend against a hacker deploying another canister and sending large inter-canister payloads to a function in a constant loop? I imagine the function logic could throttle or block repeated requests from the same principal (saving storage), but afaik, the cycles will still get drained.

Thanks.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [March 4, 2022, 4:05am UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/2 "2022-03-04T04:05:30Z")

</div>

Bump. What is the status of inspect\_message for motoko?

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [March 9, 2022, 6:21pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/3 "2022-03-09T18:21:45Z")

</div>

Stalled in bikeshedding [Feature: support system method `inspect-message` · Issue #2528 · dfinity/motoko · GitHub](https://github.com/dfinity/motoko/issues/2528)

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [April 18, 2022, 3:41am UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/4 "2022-04-18T03:41:47Z")

</div>

Will this be taken up again soon? I think inspect\_message can be really valuable to use for early authentication in order to prevent cycle drainage attacks.

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [April 23, 2022, 7:31pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/5 "2022-04-23T19:31:12Z")

</div>

I may have a go at this this week.

If you have an strong opinion about the proposals in ([Feature: support system method `inspect-message` · Issue #2528 · dfinity/motoko · GitHub](https://github.com/dfinity/motoko/issues/2528))

do chime in.

---

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [April 23, 2022, 8:00pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/6 "2022-04-23T20:00:47Z")

</div>

I have a strong opinion that it’s needed. Without the ability to intercept messages, any canister written with Motoko is vulnerable to a cycle drain attack.

---

<div class="post-metadata">

**Author:** ![lastmjs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/lastmjs/32/3406_2.png) [@lastmjs](https://forum.dfinity.org/u/lastmjs)\
**Post date:** [June 24, 2022, 9:35pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/7 "2022-06-24T21:35:49Z")

</div>

Is this live in Motoko?

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [July 5, 2022, 7:29am UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/8 "2022-07-05T07:29:34Z")

</div>

Yes, it should be. Try it from the playground.

> **[Message inspection | Internet Computer Home](https://internetcomputer.org/docs/current/developer-docs/build/languages/motoko/message-inspection/)**
>
> On the Internet Computer, a canister can selectively inspect and accept or decline ingress messages submitted through the HTTP interface:

---

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [July 6, 2022, 2:13pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/9 "2022-07-06T14:13:07Z")

</div>

Thank you Claudio!!!

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [November 16, 2022, 5:54am UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/10 "2022-11-16T05:54:41Z")

</div>

I’m currently unable to restrict query or shared query functions with `inspect_message` (update calls work fine).

I took the example from the documentation and put it on the playground.

[https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=4144018877](https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=4144018877)

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [November 17, 2022, 4:50pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/11 "2022-11-17T16:50:59Z")

</div>

Its probably not kicking in for queries because the playground issues them as query, not update, ingress messages. But I’m not sure.

---

<div class="post-metadata">

**Author:** ![chenyan](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@chenyan](https://forum.dfinity.org/u/chenyan)\
**Post date:** [November 18, 2022, 7:32pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/12 "2022-11-18T19:32:11Z")

</div>

`inspect_message` doesn’t apply to query calls. See the interface spec: [The Internet Computer Interface Specification | Internet Computer Home](https://internetcomputer.org/docs/current/references/ic-interface-spec#system-api-inspect-message)

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [November 18, 2022, 7:52pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/13 "2022-11-18T19:52:28Z")

</div>

Got it, thanks!

@claudio then the docs [here](https://internetcomputer.org/docs/current/developer-docs/build/cdks/motoko-dfinity/message-inspection/#example) should remove the query call from the `inspect_message` call? Does it make sense for query calls to be included in the `msg` arg since they won’t be blocked regardless of the boolean returned?

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [November 24, 2022, 6:15pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/14 "2022-11-24T18:15:55Z")

</div>

Confusingly, a `shared query` function _can_ be called using a regular HTTP call to obtain a certified response: this is why the variant type also includes `shared query` functions.

You would probably need to use dfx with a manually issued, certified (not plain) query to observe the filtering.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [November 24, 2022, 9:48pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/15 "2022-11-24T21:48:16Z")

</div>

If you are trying to restrict something you could force an update by using the http\_upgrade header which would force an update.

---

<div class="post-metadata">

**Author:** ![icme](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icme/32/4327_2.png) [@icme](https://forum.dfinity.org/u/icme)\
**Post date:** [November 25, 2022, 12:13am UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/16 "2022-11-25T00:13:38Z")

</div>

A “nice-to-have” would be if inspect\_message could apply to query calls as well. Any idea how difficult this change would be?

---

<div class="post-metadata">

**Author:** ![chenyan](https://avatars.discourse-cdn.com/v4/letter/c/35a633/32.png) [@chenyan](https://forum.dfinity.org/u/chenyan)\
**Post date:** [November 25, 2022, 4:22am UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/17 "2022-11-25T04:22:49Z")

</div>

Okay, I’m confused. You mean I can call the `shared query` function as an update method, and this update call can be filtered by `inspect_messge`? Is this mentioned in the spec?

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [November 25, 2022, 6:43am UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/18 "2022-11-25T06:43:00Z")

</div>

> [@icme](#):
>
> A “nice-to-have” would be if inspect\_message could apply to query calls as well. Any idea how difficult this change would be?

I understood that inspect\_message is there so that you can run some code on one replica first before it goes through the expensive process of being run on all replicas. So for a query call (that is called as a query call) you can just put the filtering code directly into the query function. You don’t need inspect\_message to achieve the same result.

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [November 30, 2022, 7:16pm UTC](https://forum.dfinity.org/t/inspect-message-for-motoko/10430/19 "2022-11-30T19:16:43Z")

</div>

> [@chenyan](#):
>
> Okay, I’m confused. You mean I can call the `shared query` function as an update method, and this update call can be filtered by `inspect_messge`? Is this mentioned in the spec?

Yes, I believe so, if you squint at the spec. The calls goes through concensus, state changes are transient, and filtering is applied. IIRC.
