Skip to content

Commit ed5cfab

Browse files
committed
Address Copilot review feedback on replace parameter validation
- Extract hardcoded 4096 length limit to URI_REPLACE_MAX_LENGTH constant - Validate hint entries have both identifier and hint value - Validate txrep entries have non-empty path values
1 parent 968832d commit ed5cfab

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

@stellar/typescript-wallet-sdk/src/walletSdk/Types/sep7.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum Sep7OperationType {
66
}
77

88
export const URI_MSG_MAX_LENGTH = 300;
9+
export const URI_REPLACE_MAX_LENGTH = 4096;
910

1011
export type Sep7Replacement = {
1112
id: string;

@stellar/typescript-wallet-sdk/src/walletSdk/Uri/sep7Parser.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
IsValidSep7UriResult,
88
WEB_STELLAR_SCHEME,
99
URI_MSG_MAX_LENGTH,
10+
URI_REPLACE_MAX_LENGTH,
1011
} from "../Types";
1112
import {
1213
Sep7InvalidUriError,
@@ -162,7 +163,7 @@ export const sep7ReplacementsFromString = (
162163
return [];
163164
}
164165

165-
if (replacements.length > 4096) {
166+
if (replacements.length > URI_REPLACE_MAX_LENGTH) {
166167
throw new Sep7InvalidUriError(
167168
"the 'replace' parameter exceeds the maximum allowed length",
168169
);
@@ -174,9 +175,9 @@ export const sep7ReplacementsFromString = (
174175
const txrepIds: string[] = [];
175176
txrepList.forEach((item) => {
176177
const parts = item.split(ID_DELIMITER);
177-
if (parts.length < 2 || !parts[1]) {
178+
if (parts.length < 2 || !parts[0] || !parts[1]) {
178179
throw new Sep7InvalidUriError(
179-
"the 'replace' parameter has an entry missing a reference identifier",
180+
"the 'replace' parameter has an entry missing a path or reference identifier",
180181
);
181182
}
182183
const id = parts[1];
@@ -189,9 +190,15 @@ export const sep7ReplacementsFromString = (
189190

190191
if (hintsString) {
191192
const hintsList = hintsString.split(LIST_DELIMITER);
192-
hintsList
193-
.map((item) => item.split(ID_DELIMITER))
194-
.forEach(([id, hint]) => (hintsMap[id] = hint));
193+
hintsList.forEach((item) => {
194+
const parts = item.split(ID_DELIMITER);
195+
if (parts.length < 2 || !parts[0] || !parts[1]) {
196+
throw new Sep7InvalidUriError(
197+
"the 'replace' parameter has a hint entry missing an identifier or hint value",
198+
);
199+
}
200+
hintsMap[parts[0]] = parts[1];
201+
});
195202
}
196203

197204
const hintIds = Object.keys(hintsMap);

0 commit comments

Comments
 (0)