harden: show a personal message's hex and its text in byte order, hidden characters marked (closes #403)
The signature screen showed only the text a personal message decodes to, with bidirectional, right-to-left and zero-width characters acting on it, so a site could make the message read differently from the bytes that are signed, and a message that was not hex was decoded into NUL characters. The screen now shows the hex as "Raw data" alongside the text, lays the text out left to right in byte order, and shows each control character, line and paragraph separator, and character that paints nothing (the set src/shared/symbolSpoof.js already strips) as a U+XXXX mark. A message is hex when getBytes, which signing uses, reads it; one that is not cannot be signed, so it is shown as plain text with "Sign" disabled. Model: opus-5-5
This commit was merged in pull request #435.
This commit is contained in:
@@ -34,6 +34,11 @@ function normalizeAddress(addr) {
|
||||
return (addr || "").toLowerCase();
|
||||
}
|
||||
|
||||
// The characters that paint nothing; normalizeSymbol below says which they
|
||||
// are. The signature screen marks them in a personal message
|
||||
// (src/popup/views/approval.js).
|
||||
const INVISIBLE_CHARACTERS = /[\p{Cf}\p{Default_Ignorable_Code_Point}\x7F]/gu;
|
||||
|
||||
// Fold a symbol onto what a user actually sees, and no further:
|
||||
//
|
||||
// NFKC collapses compatibility variants that render as the ASCII
|
||||
@@ -82,7 +87,7 @@ function normalizeAddress(addr) {
|
||||
function normalizeSymbol(symbol) {
|
||||
return String(symbol || "")
|
||||
.normalize("NFKC")
|
||||
.replace(/[\p{Cf}\p{Default_Ignorable_Code_Point}\x7F]/gu, "")
|
||||
.replace(INVISIBLE_CHARACTERS, "")
|
||||
.trim()
|
||||
.toUpperCase();
|
||||
}
|
||||
@@ -104,5 +109,6 @@ function isSpoofedSymbol(symbol, contractAddress) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
INVISIBLE_CHARACTERS,
|
||||
isSpoofedSymbol,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user