这不是安全风险吗?



我即将在一个网站上实现支付。

我见过类似于使用这个Javascript代码的解决方案

function onBuyClicked() {
if (!window.PaymentRequest) {
// PaymentRequest API is not available. Forwarding to
// legacy form based experience.
location.href = '/checkout';
return;
}
// Supported payment methods
var supportedInstruments = [{
supportedMethods: ['basic-card'],
data: {
supportedNetworks: [
'visa', 'mastercard', 'amex', 'discover',
'diners', 'jcb', 'unionpay'
]
}
}];
// Checkout details
var details = {
displayItems: [{
label: 'Original donation amount',
amount: { currency: 'USD', value: '65.00' }
}, {
label: 'Friends and family discount',
amount: { currency: 'USD', value: '-10.00' }
}],
total: {
label: 'Total due',
amount: { currency: 'USD', value : '55.00' }
}
};
// 1. Create a `PaymentRequest` instance
var request = new PaymentRequest(supportedInstruments, details);
// 2. Show the native UI with `.show()`
request.show()
// 3. Process the payment
.then(result => {
// POST the payment information to the server
return fetch('/pay', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(result.toJSON())
}).then(response => {
// 4. Display payment results
if (response.status === 200) {
// Payment successful
return result.complete('success');
} else {
// Payment failure
return result.complete('fail');
}
}).catch(() => {
return result.complete('fail');
});
});
}
document.querySelector('#start').addEventListener('click', onBuyClicked);

但是,对于任何查看页面源代码的人来说,Javascript中的这段代码都是完全可见的。

更重要的是,假设我想将成功的购买存储到我的服务器上。帖子将可见。

这不是安全风险吗?

有什么办法保护这个吗?

只要JS代码不暴露您应该提供给支付网关的任何凭据,您就安全了。

所提供的示例是围绕Payment Request生态系统构建的,该系统是收集客户端支付凭证的本地浏览器方法。

如果攻击者要从代码中学习你的支付方法,他所能做的所有黑客攻击都仅限于支付——这很好。

这不是安全风险吗?

仅当服务器端代码相信从客户端提交的成本而不进行检查时。

相关内容

最新更新