@azteam/express 1.2.461 → 1.2.466

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/Server.js CHANGED
@@ -135,9 +135,9 @@ var Server = /*#__PURE__*/function () {
135
135
  app.use((0, _cookieParser["default"])(process.env.SECRET_KEY));
136
136
  app.use((0, _compression["default"])());
137
137
  app.use((0, _cors["default"])(function (req, callback) {
138
- var origin = req.header('Origin'),
139
- authorization = req.header('Authorization'),
140
- agent = req.header('User-Agent') || 'null';
138
+ var origin = req.get('Origin'),
139
+ authorization = req.get('Authorization'),
140
+ agent = req.get('User-Agent') || 'null';
141
141
  var error = null;
142
142
  if (!authorization && !agent.startsWith(systemUser)) {
143
143
  if (origin && whiteList && !whiteList.some(function (re) {
@@ -262,7 +262,7 @@ var Server = /*#__PURE__*/function () {
262
262
  req.rootDomain = req.hostname ? _psl["default"].parse(req.hostname).domain : null;
263
263
  req.trackDevice = {
264
264
  ip: req.ip,
265
- forward_ip: req.headers['X-Forwarded-For'],
265
+ forward_ip: req.get('X-Forwarded-For'),
266
266
  device: req.get('X-DEVICE') || req.get('User-Agent'),
267
267
  device_id: req.get('X-DEVICE-ID') || 'web',
268
268
  os: req.get('X-OS') || 'web'
@@ -27,7 +27,7 @@ function _default() {
27
27
  break;
28
28
  }
29
29
  etagHash = (0, _etag["default"])(req.url + floorToMinute(Math.floor(Date.now() / 1000), mTimeout));
30
- if (!(req.headers['if-none-match'] === etagHash)) {
30
+ if (!(req.get('if-none-match') === etagHash)) {
31
31
  _context.next = 4;
32
32
  break;
33
33
  }
@@ -92,7 +92,7 @@ function _default() {
92
92
  client = new _httpClient["default"]({
93
93
  timeout: 20000,
94
94
  headers: {
95
- 'User-Agent': req.header('User-Agent')
95
+ 'User-Agent': req.get('User-Agent')
96
96
  }
97
97
  });
98
98
  _context.next = 27;
@@ -129,7 +129,7 @@ function _default() {
129
129
  _client = new _httpClient["default"]({
130
130
  timeout: 20000,
131
131
  headers: {
132
- 'User-Agent': req.header('User-Agent'),
132
+ 'User-Agent': req.get('User-Agent'),
133
133
  Authorization: headers.authorization
134
134
  }
135
135
  });
@@ -12,24 +12,29 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
12
12
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
13
  function _default(secret) {
14
14
  var mTimeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
15
+ var isThrowError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
15
16
  return /*#__PURE__*/function () {
16
17
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, next) {
17
- var url;
18
+ var cross, url;
18
19
  return _regeneratorRuntime().wrap(function _callee$(_context) {
19
20
  while (1) switch (_context.prev = _context.next) {
20
21
  case 0:
21
- if (!req.query.sign) {
22
- _context.next = 4;
23
- break;
22
+ req.validSign = false;
23
+ if (req.query.sign) {
24
+ cross = req.get('x-proxy-pass-path');
25
+ url = "".concat(req.protocol, "://").concat(req.hostname).concat(req.originalUrl);
26
+ if (cross) {
27
+ url = url.replace(cross, '');
28
+ }
29
+ req.validSign = (0, _crypto.isValidSign)(url, secret, mTimeout);
24
30
  }
25
- url = "".concat(req.protocol, "://").concat(req.hostname).concat(req.originalUrl);
26
- if (!(0, _crypto.isValidSign)(url, secret, mTimeout)) {
31
+ if (!(isThrowError && !req.validSign)) {
27
32
  _context.next = 4;
28
33
  break;
29
34
  }
30
- return _context.abrupt("return", next());
31
- case 4:
32
35
  throw new _error.ErrorException(_error.SIGNATURE_FAILED);
36
+ case 4:
37
+ return _context.abrupt("return", next());
33
38
  case 5:
34
39
  case "end":
35
40
  return _context.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.461",
3
+ "version": "1.2.466",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
package/src/Server.js CHANGED
@@ -109,9 +109,9 @@ class Server {
109
109
  app.use(compression());
110
110
  app.use(
111
111
  cors(function (req, callback) {
112
- const origin = req.header('Origin'),
113
- authorization = req.header('Authorization'),
114
- agent = req.header('User-Agent') || 'null';
112
+ const origin = req.get('Origin'),
113
+ authorization = req.get('Authorization'),
114
+ agent = req.get('User-Agent') || 'null';
115
115
 
116
116
  let error = null;
117
117
  if (!authorization && !agent.startsWith(systemUser)) {
@@ -252,7 +252,7 @@ class Server {
252
252
 
253
253
  req.trackDevice = {
254
254
  ip: req.ip,
255
- forward_ip: req.headers['X-Forwarded-For'],
255
+ forward_ip: req.get('X-Forwarded-For'),
256
256
  device: req.get('X-DEVICE') || req.get('User-Agent'),
257
257
  device_id: req.get('X-DEVICE-ID') || 'web',
258
258
  os: req.get('X-OS') || 'web',
@@ -9,7 +9,7 @@ export default function (mTimeout = 5) {
9
9
  return async function (req, res, next) {
10
10
  if (req.method === 'GET') {
11
11
  const etagHash = etag(req.url + floorToMinute(Math.floor(Date.now() / 1000), mTimeout));
12
- if (req.headers['if-none-match'] === etagHash) {
12
+ if (req.get('if-none-match') === etagHash) {
13
13
  return res.status(304).send();
14
14
  }
15
15
  res.setHeader('ETag', etagHash);
@@ -60,7 +60,7 @@ export default function (roles = null, minLevel = USER_LEVEL.USER, opts = {}) {
60
60
  const client = new HttpClient({
61
61
  timeout: 20000,
62
62
  headers: {
63
- 'User-Agent': req.header('User-Agent'),
63
+ 'User-Agent': req.get('User-Agent'),
64
64
  },
65
65
  }),
66
66
  response = await client.get(authAPIURL);
@@ -87,7 +87,7 @@ export default function (roles = null, minLevel = USER_LEVEL.USER, opts = {}) {
87
87
  const client = new HttpClient({
88
88
  timeout: 20000,
89
89
  headers: {
90
- 'User-Agent': req.header('User-Agent'),
90
+ 'User-Agent': req.get('User-Agent'),
91
91
  Authorization: headers.authorization,
92
92
  },
93
93
  }),
@@ -1,14 +1,21 @@
1
1
  import {isValidSign} from '@azteam/crypto';
2
2
  import {ErrorException, SIGNATURE_FAILED} from '@azteam/error';
3
3
 
4
- export default function (secret, mTimeout = 5) {
4
+ export default function (secret, mTimeout = 5, isThrowError = true) {
5
5
  return async function (req, res, next) {
6
+ req.validSign = false;
6
7
  if (req.query.sign) {
7
- const url = `${req.protocol}://${req.hostname}${req.originalUrl}`;
8
- if (isValidSign(url, secret, mTimeout)) {
9
- return next();
8
+ const cross = req.get('x-proxy-pass-path');
9
+ let url = `${req.protocol}://${req.hostname}${req.originalUrl}`;
10
+ if (cross) {
11
+ url = url.replace(cross, '');
10
12
  }
13
+ req.validSign = isValidSign(url, secret, mTimeout);
11
14
  }
12
- throw new ErrorException(SIGNATURE_FAILED);
15
+ if (isThrowError && !req.validSign) {
16
+ throw new ErrorException(SIGNATURE_FAILED);
17
+ }
18
+
19
+ return next();
13
20
  };
14
21
  }