safe_curl.js 535 B

123456789101112131415161718
  1. 'use strict';
  2. /**
  3. * safe curl with ssrf protect
  4. * @param {String} url request url
  5. * @param {Object} options request options
  6. * @return {Promise} response
  7. */
  8. module.exports = function safeCurl(url, options = {}) {
  9. const config = this.config || this.app.config;
  10. if (config.security.ssrf && config.security.ssrf.checkAddress) {
  11. options.checkAddress = config.security.ssrf.checkAddress;
  12. } else {
  13. this.logger.warn('[egg-security] please configure `config.security.ssrf` first');
  14. }
  15. return this.curl(url, options);
  16. };