Skip to content

Commit 6f0bb88

Browse files
Merge pull request from GHSA-6cgh-hjpw-q3gq
* Add test to ensure readChallengeTx verifies the server signed the challenge * Fix readChallengeTx not verifying server signature * Update changelog * Update version
1 parent ac46a8d commit 6f0bb88

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ A breaking change will get clearly marked in this log.
44

55
## Unreleased
66

7+
## [v8.2.3](https://github.com/stellar/js-stellar-sdk/compare/v8.2.2...v8.2.3)
8+
9+
### Fix
10+
- Fix server signature verification in `Utils.readChallengeTx`. The function was
11+
not verifying the server account had signed the challenge transaction.
712

813
## [v8.2.2](https://github.com/stellar/js-stellar-sdk/compare/v8.2.1...v8.2.2)
914

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stellar-sdk",
3-
"version": "8.2.2",
3+
"version": "8.2.3",
44
"description": "stellar-sdk is a library for working with the Stellar Horizon server.",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ export namespace Utils {
265265
}
266266
}
267267

268+
if (!verifyTxSignedBy(transaction, serverAccountID)) {
269+
throw new InvalidSep10ChallengeError(
270+
`Transaction not signed by server: '${serverAccountID}'`,
271+
);
272+
}
273+
268274
return { tx: transaction, clientAccountID, matchedHomeDomain };
269275
}
270276

test/unit/utils_test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,41 @@ describe('Utils', function() {
216216
});
217217
});
218218

219+
it("throws an error if the server hasn't signed the transaction", function () {
220+
let serverKP = StellarSdk.Keypair.random();
221+
let clientKP = StellarSdk.Keypair.random();
222+
223+
const transaction = new StellarSdk.TransactionBuilder(
224+
new StellarSdk.Account(serverKP.publicKey(), "-1"),
225+
{ fee: 100, networkPassphrase: StellarSdk.Networks.TESTNET },
226+
)
227+
.addOperation(StellarSdk.Operation.manageData({
228+
source: clientKP.publicKey(),
229+
name: "SDF-test auth",
230+
value: randomBytes(48).toString("base64"),
231+
}))
232+
.setTimeout(30)
233+
.build();
234+
235+
const challenge = transaction
236+
.toEnvelope()
237+
.toXDR("base64")
238+
.toString();
239+
240+
expect(() =>
241+
StellarSdk.Utils.readChallengeTx(
242+
challenge,
243+
serverKP.publicKey(),
244+
StellarSdk.Networks.TESTNET,
245+
"SDF-test",
246+
"testanchor.stellar.org"
247+
),
248+
).to.throw(
249+
StellarSdk.InvalidSep10ChallengeError,
250+
"Transaction not signed by server: '" + serverKP.publicKey() + "'",
251+
);
252+
});
253+
219254
it("throws an error if transaction sequenceNumber is different to zero", function() {
220255
let keypair = StellarSdk.Keypair.random();
221256

0 commit comments

Comments
 (0)