Skip to content

Fix secu issues - #1099

Merged
cedelavergne-ledger merged 15 commits into
developfrom
cev/fix_secu_issues
Aug 17, 2026
Merged

cedelavergne-ledger merged 15 commits into
developfrom
cev/fix_secu_issues

Conversation

@cedelavergne-ledger

@cedelavergne-ledger cedelavergne-ledger commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Fix return code type in APDU handle
  • Fix(eip712): track PREPARING state and restrict ui_712_init bzero scope
  • Fix(erc1155): bound pair_idx before accessing batch_ids/batch_values
  • Fix(eip712): address security findings
  • Fix(eip712): remove shared strings union from struct name staging
  • Fix(context): clear dataContext in reset_app_context()
  • Fix(network): guard cleanup against NULL g_last_added_network
  • Test(unit): adapt network_info tests for cleanup NULL guard
  • Fix(nbgl): zero pairs list header before freeing backing array
  • Fix(plugin): add discriminant for pluginContext/contractAddress union
  • Fix(eip712): pin hash display strings in signing context
  • Fix(eip712): remove redundant reset_app_context() from approve/reject
  • Cleanup eip712 message review callbacks

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Tests
  • Documentation
  • Other (for changes that might not fit in any category)

eip712_v1_context_init() now sets appState = APP_STATE_PREPARING_EIP712
on success so that handle_first_sign_chunk()'s APP_STATE_IDLE guard blocks
any interleaved INS_SIGN during the struct-definition phase.

ui_712_init() restricts its explicit_bzero to strings.tmp.tmp instead of
the whole strings union; the EIP-712 init path has no business clearing
strings.common, which may belong to another flow.
set_batch_transfer_ui() derived pair_idx from the screen index without
checking it against ERC1155_BATCH_DISPLAY_MAX before indexing into
batch_ids[] and batch_values[]. An out-of-range screen index would
access stale context memory, so return ETH_PLUGIN_RESULT_ERROR instead.
- v1_set_array: reject re-entry when array_remaining > 0 but
  array_levels_remaining == 0; prevents re-opening a leaf-level
  array frame that is still consuming elements

- filtering handlers: add `if (discarded) return true;` at the
  start of the Handling section in all ten filter handlers that
  were missing the guard (filtering_calldata_{spender,amount,
  selector,chain_id,callee,value}, filtering_trusted_name,
  filtering_date_time, filtering_amount_join_{token,value});
  filtering_raw_field was already the only correct one

- ui_712_start_review: call set_tx_simulation_warning() before
  ui_tx_simulation_finish_str() so the finish button label
  reflects the actual simulation verdict
@cedelavergne-ledger
cedelavergne-ledger requested a review from a team as a code owner August 14, 2026 08:39
@github-actions

github-actions Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

elf sizes
source = source branch cev/fix_secu_issues
target = target branch develop

Device .text source .text target .text delta .bss source .bss target .bss delta max stack size source max stack size target max stack size delta
nanos2 125539 125539 0 21964 21956 8 18988 18996 -8
apex_p 171161 171161 0 23268 23260 8 17684 17692 -8
stax 191742 191742 0 23268 23260 8 13588 13596 -8
flex 191821 191821 0 23268 23260 8 13588 13596 -8
nanox 125283 125283 0 21980 21972 8 8192 8192 0

Stack consumption summary (clone_app_stack_consumption)

⚠️ This summary is for informative purpose only. It may not give the application actual worst case, for example if the test coverage is low.

Device Worst case (bytes) Remaining stack (bytes) Test
apex_p 2833 37747 test_clone.py::test_clone_thundercore_tx[apex_p]
flex 2881 33603 test_clone.py::test_clone_thundercore_tx[flex]
nanosp 2705 38063 test_clone.py::test_clone_thundercore_tx[nanosp]
nanox 2697 25783 test_clone.py::test_clone_thundercore_tx[nanox]
stax 2881 33603 test_clone.py::test_clone_thundercore_tx[stax]

Full details

Stack consumption summary

⚠️ This summary is for informative purpose only. It may not give the application actual worst case, for example if the test coverage is low.

Device Worst case (bytes) Remaining stack (bytes) Test
apex_p 5821 11863 test_gcs_formatters.py::test_gcs_group_sequential[apex_p]
flex 5821 7767 test_gcs_formatters.py::test_gcs_group_sequential[flex]
nanosp 5829 13159 test_gcs_formatters.py::test_gcs_group_sequential[nanosp]
nanox 5833 851 test_gcs_formatters.py::test_gcs_group_sequential[nanox]
stax 5821 7767 test_gcs_formatters.py::test_gcs_group_sequential[stax]

Full details

@codecov-commenter

codecov-commenter commented Aug 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.70588% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.58%. Comparing base (c29d818) to head (92b1930).

Files with missing lines Patch % Lines
...features/sign_message_eip712/eip712_v1_filtering.c 0.00% 10 Missing ⚠️
...c/features/sign_message_eip712_common/common_712.c 75.00% 2 Missing and 2 partials ⚠️
src/features/sign_message/cmd_sign_message.c 25.00% 3 Missing ⚠️
src/features/sign_message_eip712/eip712_v1_parse.c 80.00% 1 Missing and 1 partial ⚠️
src/plugins/erc1155/erc1155_ui.c 33.33% 2 Missing ⚠️
src/plugins/eth_plugin_handler.c 50.00% 2 Missing ⚠️
src/nbgl/ui_message_signing.c 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1099      +/-   ##
===========================================
- Coverage    74.71%   74.58%   -0.14%     
===========================================
  Files          162      162              
  Lines        14623    14659      +36     
  Branches      3505     3529      +24     
===========================================
+ Hits         10926    10933       +7     
- Misses        3457     3481      +24     
- Partials       240      245       +5     
Flag Coverage Δ
functionaltests 81.52% <75.00%> (+0.04%) ⬆️
fuzzing 42.90% <42.64%> (-0.24%) ⬇️
unittests 86.64% <50.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-code-quality

github-code-quality Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Code Coverage Overview

Languages: C

C / code-coverage/unittests

The overall coverage in commit 92b1930 in the cev/fix_secu_issues branch is 93%. Coverage data for the develop branch is not yet available.

Show a code coverage summary of the most covered files.
File develop cev/fix_secu_issues 92b1930 +/-
src/uint256.c — 100% —
src/plugins/eth...lugin_handler.c — 96% —
src/features/ge...ser/gtp_field.c — 95% —
src/features/si...x/eth_ustream.c — 94% —
src/features/ge...gtp_param_raw.c — 94% —
src/features/pr.../trusted_name.c — 90% —
src/features/pr...md_get_gating.c — 89% —
src/features/ge...gtp_data_path.c — 89% —
src/features/pr...tx_simulation.c — 89% —
src/features/si...logic_sign_tx.c — 83% —

Updated August 17, 2026 07:56 UTC

v1_set_struct_name() was using strings.tmp.tmp as a scratch buffer to
null-terminate the incoming struct name before passing it to
td_create_struct_def(). strings.tmp.tmp aliases strings.common (same
union), so any write during an active review silently corrupts the
displayed fromAddress, toAddress and other fields.

Allocate an exact-sized temporary buffer via APP_MEM_ALLOC, pass it to
td_create_struct_def() which makes its own copy, then immediately free.
tokenContext_t (plugin name, contract address, method selector,
pluginChainId, pluginStatus, token lookups) was never zeroed between
signing sessions, allowing stale plugin/token state from a previous
transaction to bleed into the next one.

Add memset(&dataContext) alongside the existing clears of tmpCtx,
txContext and tmpContent.
Every error path in handle_network_info() called
network_info_cleanup(g_last_added_network) unconditionally.
network_info_cleanup(NULL) erases the entire dynamic network list, so a
single malformed PROVIDE_NETWORK_INFO APDU sent before any network was
registered wiped all previously loaded networks and freed any icons held
by live reviews.

Add a NULL check before each cleanup call on error paths.
`test_get_info_invalid_p1_rejected` now sets up an in-flight network
before the call so the NULL guard does not suppress the cleanup, and
asserts that cleanup received the correct pointer.

Added `test_get_info_invalid_p1_no_in_flight_no_cleanup` to verify that
cleanup is skipped when `g_last_added_network` is NULL, preventing the
unintended deletion of the entire dynamic network list.
ui_pairs_cleanup() was freeing g_pairs while NBGL could still hold a
pointer to the backing array via g_pairsList->pairs. Any render callback
firing between the free and the next idle screen would dereference freed
memory.

Clear g_pairsList->pairs and nbPairs before APP_MEM_FREE_AND_NULL so
that any in-flight NBGL callback finds an empty list rather than a
dangling pointer.
tokenContext_t contains an anonymous union where pluginContext[1024]
aliases contractAddress[20]+methodSelector[4] at offset 0. Nothing
prevented code from reading contractAddress after INIT_CONTRACT had
overwritten those bytes with plugin-private data.

Add a plugin_ctx_mode_t enum (PLUGIN_CTX_ADDR_SEL / PLUGIN_CTX_PLUGIN)
that tracks which half of the union is active. The discriminant is set to
PLUGIN_CTX_PLUGIN just before eth_plugin_call(INIT_CONTRACT) activates
the plugin context. An early app_exit() in eth_plugin_perform_init_default()
fires if the flag is already set, catching double-INIT_CONTRACT attempts
that would read stale plugin bytes as an address/selector.
eip712_format_hash() was storing NBGL display pointers directly into
strings.tmp.tmp, a scratch buffer shared with every other signing flow.
Any APDU processed while the EIP-712 review is displayed (the APDU loop
stays alive on SWO_NO_RESPONSE) could silently overwrite the domain/
message hash strings without NBGL noticing.
ui_712_approve() and ui_712_reject() explicitly called reset_app_context()
after the _cb, but io_seproxyhal_send_status(..., true, ...) — which both
_cb functions call — already invokes reset_app_context() synchronously
before the APDU response is sent. The wrappers were therefore double-
resetting the context.

With the extra reset removed, the wrappers become trivial pass-throughs.
Remove them entirely and have ui_typed_message_review_choice() call
ui_712_approve_cb/ui_712_reject_cb directly, matching what the v0 path
already did.
Comment thread src/nbgl/ui_sign_712.c Fixed
final_process() frees g_msg_hash_ctx on success but leaves signMsgCtx
live for the UI. A subsequent P1_MORE with length=0 bypassed the length
check ((0 + N) > N is false) and re-entered final_process() with a NULL
hash context, causing a null-pointer dereference.

Guard against this by checking g_msg_hash_ctx != NULL before processing
any further data.
@github-actions

Copy link
Copy Markdown
Contributor

Code coverage report

Code Coverage

Per-file coverage
Package Line Rate Branch Rate Health
src 99% 98% ✔
src.features.generic_tx_parser 93% 81% ✔
src.features.get_app_configuration 100% 100% ✔
src.features.get_challenge 100% 100% ✔
src.features.get_eth2_public_key 98% 93% ✔
src.features.get_public_key 98% 97% ✔
src.features.perform_privacy_operation 98% 86% ✔
src.features.provide_enum_value 96% 87% ✔
src.features.provide_erc20_token_information 94% 88% ✔
src.features.provide_gating 89% 82% ✔
src.features.provide_map_entry 93% 76% ✔
src.features.provide_network_info 90% 81% ✔
src.features.provide_nft_information 91% 80% ✔
src.features.provide_proxy_info 97% 89% ✔
src.features.provide_safe_account 95% 88% ✔
src.features.provide_trusted_name 90% 82% ✔
src.features.provide_tx_simulation 89% 85% ✔
src.features.set_eth2_withdrawal_index 100% 100% ✔
src.features.set_external_plugin 89% 80% ✔
src.features.set_plugin 95% 90% ✔
src.features.sign_authorization_eip7702 87% 80% ✔
src.features.sign_message 88% 75% ✔
src.features.sign_tx 89% 79% ✔
src.nbgl 98% 87% ✔
src.plugins.eip7002 95% 87% ✔
src.plugins.eip7251 97% 87% ✔
src.plugins.erc1155 91% 81% ✔
src.plugins.erc20 91% 86% ✔
src.plugins.erc721 94% 86% ✔
src.plugins.eth2 94% 90% ✔
src.plugins 96% 90% ✔
src.plugins.swap_with_calldata 98% 94% ✔
src.swap 96% 93% ✔
src.utils 93% 90% ✔
Summary 93% (6916 / 7458) 84% (3386 / 4039) ✔

@cedelavergne-ledger
cedelavergne-ledger merged commit 9438102 into develop Aug 17, 2026
329 checks passed
@cedelavergne-ledger
cedelavergne-ledger deleted the cev/fix_secu_issues branch August 17, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants