@eggjs/security 4.0.1 → 5.0.0-beta.15

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.
Files changed (252) hide show
  1. package/README.md +46 -66
  2. package/README.zh-CN.md +56 -68
  3. package/dist/agent.d.ts +10 -0
  4. package/dist/agent.js +15 -0
  5. package/dist/app/extend/agent.d.ts +14 -0
  6. package/dist/app/extend/agent.js +12 -0
  7. package/dist/app/extend/application.d.ts +20 -0
  8. package/dist/app/extend/application.js +32 -0
  9. package/dist/app/extend/context.d.ts +74 -0
  10. package/dist/app/extend/context.js +191 -0
  11. package/dist/app/extend/helper.d.ts +24 -0
  12. package/dist/app/extend/helper.js +7 -0
  13. package/dist/app/extend/response.d.ts +45 -0
  14. package/dist/app/extend/response.js +70 -0
  15. package/dist/app/middleware/securities.d.ts +8 -0
  16. package/dist/app/middleware/securities.js +39 -0
  17. package/dist/app.d.ts +10 -0
  18. package/dist/app.js +24 -0
  19. package/dist/config/config.default.d.ts +874 -0
  20. package/dist/config/config.default.js +170 -0
  21. package/dist/config/config.local.d.ts +6 -0
  22. package/dist/config/config.local.js +5 -0
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +3 -0
  25. package/dist/lib/extend/safe_curl.d.ts +20 -0
  26. package/dist/lib/extend/safe_curl.js +19 -0
  27. package/dist/lib/helper/cliFilter.d.ts +7 -0
  28. package/dist/lib/helper/cliFilter.js +18 -0
  29. package/dist/lib/helper/escape.d.ts +2 -0
  30. package/dist/lib/helper/escape.js +7 -0
  31. package/dist/lib/helper/escapeShellArg.d.ts +4 -0
  32. package/dist/lib/helper/escapeShellArg.js +7 -0
  33. package/dist/lib/helper/escapeShellCmd.d.ts +4 -0
  34. package/dist/lib/helper/escapeShellCmd.js +15 -0
  35. package/dist/lib/helper/index.d.ts +24 -0
  36. package/dist/lib/helper/index.js +25 -0
  37. package/dist/lib/helper/shtml.d.ts +6 -0
  38. package/dist/lib/helper/shtml.js +53 -0
  39. package/dist/lib/helper/sjs.d.ts +7 -0
  40. package/dist/lib/helper/sjs.js +36 -0
  41. package/dist/lib/helper/sjson.d.ts +4 -0
  42. package/dist/lib/helper/sjson.js +32 -0
  43. package/dist/lib/helper/spath.d.ts +7 -0
  44. package/dist/lib/helper/spath.js +16 -0
  45. package/dist/lib/helper/surl.d.ts +6 -0
  46. package/dist/lib/helper/surl.js +25 -0
  47. package/dist/lib/middlewares/csp.d.ts +7 -0
  48. package/dist/lib/middlewares/csp.js +46 -0
  49. package/dist/lib/middlewares/csrf.d.ts +7 -0
  50. package/dist/lib/middlewares/csrf.js +33 -0
  51. package/dist/lib/middlewares/dta.d.ts +6 -0
  52. package/dist/lib/middlewares/dta.js +13 -0
  53. package/dist/lib/middlewares/hsts.d.ts +7 -0
  54. package/dist/lib/middlewares/hsts.js +19 -0
  55. package/dist/lib/middlewares/index.d.ts +18 -0
  56. package/dist/lib/middlewares/index.js +27 -0
  57. package/dist/lib/middlewares/methodnoallow.d.ts +6 -0
  58. package/dist/lib/middlewares/methodnoallow.js +15 -0
  59. package/dist/lib/middlewares/noopen.d.ts +7 -0
  60. package/dist/lib/middlewares/noopen.js +17 -0
  61. package/dist/lib/middlewares/nosniff.d.ts +7 -0
  62. package/dist/lib/middlewares/nosniff.js +27 -0
  63. package/dist/lib/middlewares/referrerPolicy.d.ts +7 -0
  64. package/dist/lib/middlewares/referrerPolicy.js +31 -0
  65. package/dist/lib/middlewares/xframe.d.ts +7 -0
  66. package/dist/lib/middlewares/xframe.js +18 -0
  67. package/dist/lib/middlewares/xssProtection.d.ts +7 -0
  68. package/dist/lib/middlewares/xssProtection.js +17 -0
  69. package/dist/lib/utils.d.ts +24 -0
  70. package/dist/lib/utils.js +127 -0
  71. package/dist/types.d.ts +12 -0
  72. package/dist/types.js +5 -0
  73. package/package.json +74 -70
  74. package/dist/commonjs/agent.d.ts +0 -6
  75. package/dist/commonjs/agent.js +0 -14
  76. package/dist/commonjs/app/extend/agent.d.ts +0 -5
  77. package/dist/commonjs/app/extend/agent.js +0 -11
  78. package/dist/commonjs/app/extend/application.d.ts +0 -16
  79. package/dist/commonjs/app/extend/application.js +0 -35
  80. package/dist/commonjs/app/extend/context.d.ts +0 -68
  81. package/dist/commonjs/app/extend/context.js +0 -283
  82. package/dist/commonjs/app/extend/helper.d.ts +0 -12
  83. package/dist/commonjs/app/extend/helper.js +0 -10
  84. package/dist/commonjs/app/extend/response.d.ts +0 -41
  85. package/dist/commonjs/app/extend/response.js +0 -85
  86. package/dist/commonjs/app/middleware/securities.d.ts +0 -4
  87. package/dist/commonjs/app/middleware/securities.js +0 -55
  88. package/dist/commonjs/app.d.ts +0 -6
  89. package/dist/commonjs/app.js +0 -29
  90. package/dist/commonjs/config/config.default.d.ts +0 -871
  91. package/dist/commonjs/config/config.default.js +0 -357
  92. package/dist/commonjs/config/config.local.d.ts +0 -5
  93. package/dist/commonjs/config/config.local.js +0 -10
  94. package/dist/commonjs/index.d.ts +0 -1
  95. package/dist/commonjs/index.js +0 -4
  96. package/dist/commonjs/lib/extend/safe_curl.d.ts +0 -16
  97. package/dist/commonjs/lib/extend/safe_curl.js +0 -28
  98. package/dist/commonjs/lib/helper/cliFilter.d.ts +0 -4
  99. package/dist/commonjs/lib/helper/cliFilter.js +0 -20
  100. package/dist/commonjs/lib/helper/escape.d.ts +0 -2
  101. package/dist/commonjs/lib/helper/escape.js +0 -8
  102. package/dist/commonjs/lib/helper/escapeShellArg.d.ts +0 -1
  103. package/dist/commonjs/lib/helper/escapeShellArg.js +0 -8
  104. package/dist/commonjs/lib/helper/escapeShellCmd.d.ts +0 -1
  105. package/dist/commonjs/lib/helper/escapeShellCmd.js +0 -17
  106. package/dist/commonjs/lib/helper/index.d.ts +0 -21
  107. package/dist/commonjs/lib/helper/index.js +0 -26
  108. package/dist/commonjs/lib/helper/shtml.d.ts +0 -2
  109. package/dist/commonjs/lib/helper/shtml.js +0 -76
  110. package/dist/commonjs/lib/helper/sjs.d.ts +0 -4
  111. package/dist/commonjs/lib/helper/sjs.js +0 -52
  112. package/dist/commonjs/lib/helper/sjson.d.ts +0 -1
  113. package/dist/commonjs/lib/helper/sjson.js +0 -45
  114. package/dist/commonjs/lib/helper/spath.d.ts +0 -5
  115. package/dist/commonjs/lib/helper/spath.js +0 -28
  116. package/dist/commonjs/lib/helper/surl.d.ts +0 -2
  117. package/dist/commonjs/lib/helper/surl.js +0 -33
  118. package/dist/commonjs/lib/middlewares/csp.d.ts +0 -4
  119. package/dist/commonjs/lib/middlewares/csp.js +0 -68
  120. package/dist/commonjs/lib/middlewares/csrf.d.ts +0 -4
  121. package/dist/commonjs/lib/middlewares/csrf.js +0 -42
  122. package/dist/commonjs/lib/middlewares/dta.d.ts +0 -3
  123. package/dist/commonjs/lib/middlewares/dta.js +0 -14
  124. package/dist/commonjs/lib/middlewares/hsts.d.ts +0 -4
  125. package/dist/commonjs/lib/middlewares/hsts.js +0 -23
  126. package/dist/commonjs/lib/middlewares/index.d.ts +0 -13
  127. package/dist/commonjs/lib/middlewares/index.js +0 -28
  128. package/dist/commonjs/lib/middlewares/methodnoallow.d.ts +0 -3
  129. package/dist/commonjs/lib/middlewares/methodnoallow.js +0 -22
  130. package/dist/commonjs/lib/middlewares/noopen.d.ts +0 -4
  131. package/dist/commonjs/lib/middlewares/noopen.js +0 -17
  132. package/dist/commonjs/lib/middlewares/nosniff.d.ts +0 -4
  133. package/dist/commonjs/lib/middlewares/nosniff.js +0 -30
  134. package/dist/commonjs/lib/middlewares/referrerPolicy.d.ts +0 -4
  135. package/dist/commonjs/lib/middlewares/referrerPolicy.js +0 -36
  136. package/dist/commonjs/lib/middlewares/xframe.d.ts +0 -4
  137. package/dist/commonjs/lib/middlewares/xframe.js +0 -19
  138. package/dist/commonjs/lib/middlewares/xssProtection.d.ts +0 -4
  139. package/dist/commonjs/lib/middlewares/xssProtection.js +0 -16
  140. package/dist/commonjs/lib/utils.d.ts +0 -19
  141. package/dist/commonjs/lib/utils.js +0 -206
  142. package/dist/commonjs/package.json +0 -3
  143. package/dist/commonjs/types.d.ts +0 -10
  144. package/dist/commonjs/types.js +0 -5
  145. package/dist/esm/agent.d.ts +0 -6
  146. package/dist/esm/agent.js +0 -11
  147. package/dist/esm/app/extend/agent.d.ts +0 -5
  148. package/dist/esm/app/extend/agent.js +0 -8
  149. package/dist/esm/app/extend/application.d.ts +0 -16
  150. package/dist/esm/app/extend/application.js +0 -32
  151. package/dist/esm/app/extend/context.d.ts +0 -68
  152. package/dist/esm/app/extend/context.js +0 -244
  153. package/dist/esm/app/extend/helper.d.ts +0 -12
  154. package/dist/esm/app/extend/helper.js +0 -5
  155. package/dist/esm/app/extend/response.d.ts +0 -41
  156. package/dist/esm/app/extend/response.js +0 -82
  157. package/dist/esm/app/middleware/securities.d.ts +0 -4
  158. package/dist/esm/app/middleware/securities.js +0 -50
  159. package/dist/esm/app.d.ts +0 -6
  160. package/dist/esm/app.js +0 -26
  161. package/dist/esm/config/config.default.d.ts +0 -871
  162. package/dist/esm/config/config.default.js +0 -351
  163. package/dist/esm/config/config.local.d.ts +0 -5
  164. package/dist/esm/config/config.local.js +0 -8
  165. package/dist/esm/index.d.ts +0 -1
  166. package/dist/esm/index.js +0 -2
  167. package/dist/esm/lib/extend/safe_curl.d.ts +0 -16
  168. package/dist/esm/lib/extend/safe_curl.js +0 -25
  169. package/dist/esm/lib/helper/cliFilter.d.ts +0 -4
  170. package/dist/esm/lib/helper/cliFilter.js +0 -17
  171. package/dist/esm/lib/helper/escape.d.ts +0 -2
  172. package/dist/esm/lib/helper/escape.js +0 -3
  173. package/dist/esm/lib/helper/escapeShellArg.d.ts +0 -1
  174. package/dist/esm/lib/helper/escapeShellArg.js +0 -5
  175. package/dist/esm/lib/helper/escapeShellCmd.d.ts +0 -1
  176. package/dist/esm/lib/helper/escapeShellCmd.js +0 -14
  177. package/dist/esm/lib/helper/index.d.ts +0 -21
  178. package/dist/esm/lib/helper/index.js +0 -21
  179. package/dist/esm/lib/helper/shtml.d.ts +0 -2
  180. package/dist/esm/lib/helper/shtml.js +0 -70
  181. package/dist/esm/lib/helper/sjs.d.ts +0 -4
  182. package/dist/esm/lib/helper/sjs.js +0 -49
  183. package/dist/esm/lib/helper/sjson.d.ts +0 -1
  184. package/dist/esm/lib/helper/sjson.js +0 -39
  185. package/dist/esm/lib/helper/spath.d.ts +0 -5
  186. package/dist/esm/lib/helper/spath.js +0 -25
  187. package/dist/esm/lib/helper/surl.d.ts +0 -2
  188. package/dist/esm/lib/helper/surl.js +0 -30
  189. package/dist/esm/lib/middlewares/csp.d.ts +0 -4
  190. package/dist/esm/lib/middlewares/csp.js +0 -63
  191. package/dist/esm/lib/middlewares/csrf.d.ts +0 -4
  192. package/dist/esm/lib/middlewares/csrf.js +0 -37
  193. package/dist/esm/lib/middlewares/dta.d.ts +0 -3
  194. package/dist/esm/lib/middlewares/dta.js +0 -12
  195. package/dist/esm/lib/middlewares/hsts.d.ts +0 -4
  196. package/dist/esm/lib/middlewares/hsts.js +0 -21
  197. package/dist/esm/lib/middlewares/index.d.ts +0 -13
  198. package/dist/esm/lib/middlewares/index.js +0 -23
  199. package/dist/esm/lib/middlewares/methodnoallow.d.ts +0 -3
  200. package/dist/esm/lib/middlewares/methodnoallow.js +0 -20
  201. package/dist/esm/lib/middlewares/noopen.d.ts +0 -4
  202. package/dist/esm/lib/middlewares/noopen.js +0 -15
  203. package/dist/esm/lib/middlewares/nosniff.d.ts +0 -4
  204. package/dist/esm/lib/middlewares/nosniff.js +0 -28
  205. package/dist/esm/lib/middlewares/referrerPolicy.d.ts +0 -4
  206. package/dist/esm/lib/middlewares/referrerPolicy.js +0 -34
  207. package/dist/esm/lib/middlewares/xframe.d.ts +0 -4
  208. package/dist/esm/lib/middlewares/xframe.js +0 -17
  209. package/dist/esm/lib/middlewares/xssProtection.d.ts +0 -4
  210. package/dist/esm/lib/middlewares/xssProtection.js +0 -14
  211. package/dist/esm/lib/utils.d.ts +0 -19
  212. package/dist/esm/lib/utils.js +0 -194
  213. package/dist/esm/package.json +0 -3
  214. package/dist/esm/types.d.ts +0 -10
  215. package/dist/esm/types.js +0 -3
  216. package/dist/package.json +0 -4
  217. package/src/agent.ts +0 -14
  218. package/src/app/extend/agent.ts +0 -14
  219. package/src/app/extend/application.ts +0 -51
  220. package/src/app/extend/context.ts +0 -285
  221. package/src/app/extend/helper.ts +0 -5
  222. package/src/app/extend/response.ts +0 -95
  223. package/src/app/middleware/securities.ts +0 -63
  224. package/src/app.ts +0 -31
  225. package/src/config/config.default.ts +0 -379
  226. package/src/config/config.local.ts +0 -9
  227. package/src/index.ts +0 -1
  228. package/src/lib/extend/safe_curl.ts +0 -35
  229. package/src/lib/helper/cliFilter.ts +0 -20
  230. package/src/lib/helper/escape.ts +0 -3
  231. package/src/lib/helper/escapeShellArg.ts +0 -4
  232. package/src/lib/helper/escapeShellCmd.ts +0 -16
  233. package/src/lib/helper/index.ts +0 -21
  234. package/src/lib/helper/shtml.ts +0 -77
  235. package/src/lib/helper/sjs.ts +0 -57
  236. package/src/lib/helper/sjson.ts +0 -35
  237. package/src/lib/helper/spath.ts +0 -27
  238. package/src/lib/helper/surl.ts +0 -35
  239. package/src/lib/middlewares/csp.ts +0 -70
  240. package/src/lib/middlewares/csrf.ts +0 -44
  241. package/src/lib/middlewares/dta.ts +0 -13
  242. package/src/lib/middlewares/hsts.ts +0 -24
  243. package/src/lib/middlewares/index.ts +0 -23
  244. package/src/lib/middlewares/methodnoallow.ts +0 -23
  245. package/src/lib/middlewares/noopen.ts +0 -18
  246. package/src/lib/middlewares/nosniff.ts +0 -32
  247. package/src/lib/middlewares/referrerPolicy.ts +0 -39
  248. package/src/lib/middlewares/xframe.ts +0 -20
  249. package/src/lib/middlewares/xssProtection.ts +0 -17
  250. package/src/lib/utils.ts +0 -208
  251. package/src/types.ts +0 -16
  252. package/src/typings/index.d.ts +0 -4
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # @eggjs/security
2
2
 
3
3
  [![NPM version][npm-image]][npm-url]
4
- [![Node.js CI](https://github.com/eggjs/security/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/security/actions/workflows/nodejs.yml)
5
- [![Test coverage][codecov-image]][codecov-url]
6
4
  [![Known Vulnerabilities][snyk-image]][snyk-url]
7
5
  [![npm download][download-image]][download-url]
8
6
  [![Node.js Version](https://img.shields.io/node/v/@eggjs/security.svg?style=flat)](https://nodejs.org/en/download/)
@@ -11,8 +9,6 @@
11
9
 
12
10
  [npm-image]: https://img.shields.io/npm/v/@eggjs/security.svg?style=flat-square
13
11
  [npm-url]: https://npmjs.org/package/@eggjs/security
14
- [codecov-image]: https://codecov.io/gh/eggjs/security/branch/master/graph/badge.svg
15
- [codecov-url]: https://codecov.io/gh/eggjs/security
16
12
  [snyk-image]: https://snyk.io/test/npm/@eggjs/security/badge.svg?style=flat-square
17
13
  [snyk-url]: https://snyk.io/test/npm/@eggjs/security
18
14
  [download-image]: https://img.shields.io/npm/dm/@eggjs/security.svg?style=flat-square
@@ -88,7 +84,7 @@ exports.security = {
88
84
  };
89
85
  ```
90
86
 
91
- __mention:`match` has higher priority than `ignore`__
87
+ **mention:`match` has higher priority than `ignore`**
92
88
 
93
89
  ### Dynamic configuration for security plugins depend on context
94
90
 
@@ -109,8 +105,8 @@ async ctx => {
109
105
  // disable configuration
110
106
  ctx.securityOptions.xssProtection = {
111
107
  enable: false,
112
- }
113
- }
108
+ };
109
+ };
114
110
  ```
115
111
 
116
112
  Not all security plugins support dynamic configuration, only the following plugins list support
@@ -122,7 +118,7 @@ Not all security plugins support dynamic configuration, only the following plugi
122
118
  - xframe
123
119
  - xssProtection
124
120
 
125
- And in ` helper `:
121
+ And in `helper`:
126
122
 
127
123
  - shtml
128
124
 
@@ -130,8 +126,7 @@ helper is the same way to configure.
130
126
 
131
127
  ```js
132
128
  ctx.securityOptions.shtml = {
133
- whiteList: {
134
- },
129
+ whiteList: {},
135
130
  };
136
131
  ```
137
132
 
@@ -151,7 +146,7 @@ Note: [egg-cors](https://github.com/eggjs/egg-cors) module uses this function in
151
146
 
152
147
  ```js
153
148
  exports.security = {
154
- domainWhiteList: ['http://localhost:4200']
149
+ domainWhiteList: ['http://localhost:4200'],
155
150
  };
156
151
  ```
157
152
 
@@ -159,7 +154,7 @@ exports.security = {
159
154
 
160
155
  ### CSRF
161
156
 
162
- __usage__
157
+ **usage**
163
158
 
164
159
  - `ctx.csrf` getter for CSRF token
165
160
 
@@ -172,8 +167,7 @@ browser:
172
167
 
173
168
  ```html
174
169
  <form method="POST" action="/upload?_csrf={{ ctx.csrf | safe }}" enctype="multipart/form-data">
175
- title: <input name="title" />
176
- file: <input name="file" type="file" />
170
+ title: <input name="title" /> file: <input name="file" type="file" />
177
171
  <button type="submit">上传</button>
178
172
  </form>
179
173
  ```
@@ -189,10 +183,10 @@ var csrftoken = Cookies.get('csrftoken');
189
183
 
190
184
  function csrfSafeMethod(method) {
191
185
  // these HTTP methods do not require CSRF protection
192
- return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
186
+ return /^(GET|HEAD|OPTIONS|TRACE)$/.test(method);
193
187
  }
194
188
  $.ajaxSetup({
195
- beforeSend: function(xhr, settings) {
189
+ beforeSend: function (xhr, settings) {
196
190
  if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
197
191
  xhr.setRequestHeader('x-csrf-token', csrftoken);
198
192
  }
@@ -207,22 +201,23 @@ there are some options that you can customize:
207
201
  ```js
208
202
  exports.security = {
209
203
  csrf: {
210
- type: 'ctoken', // can be ctoken, referer, all or any, default to ctoken
211
- useSession: false, // if useSession set to true, the secret will keep in session instead of cookie
212
- ignoreJSON: false, // skip check JSON requests if ignoreJSON set to true
213
- cookieName: 'csrfToken', // csrf token's cookie name
214
- sessionName: 'csrfToken', // csrf token's session name
204
+ type: 'ctoken', // can be ctoken, referer, all or any, default to ctoken
205
+ useSession: false, // if useSession set to true, the secret will keep in session instead of cookie
206
+ ignoreJSON: false, // skip check JSON requests if ignoreJSON set to true
207
+ cookieName: 'csrfToken', // csrf token's cookie name
208
+ sessionName: 'csrfToken', // csrf token's session name
215
209
  headerName: 'x-csrf-token', // request csrf token's name in header
216
- bodyName: '_csrf', // request csrf token's name in body
217
- queryName: '_csrf', // request csrf token's name in query
218
- rotateWhenInvalid: false, // rotate csrf secret when csrf token invalid. For multi applications which be deployed on the same domain, as tokens from one application may impact others.
219
- refererWhiteList: [], // referer white list
220
- supportedRequests: [ // supported URL path and method, the package will match URL path regex patterns one by one until path matched. We recommend you set {path: /^\//, methods:['POST','PATCH','DELETE','PUT','CONNECT']} as the last rule in the list, which is also the default config.
221
- {path: /^\//, methods:['POST','PATCH','DELETE','PUT','CONNECT']}
210
+ bodyName: '_csrf', // request csrf token's name in body
211
+ queryName: '_csrf', // request csrf token's name in query
212
+ rotateWhenInvalid: false, // rotate csrf secret when csrf token invalid. For multi applications which be deployed on the same domain, as tokens from one application may impact others.
213
+ refererWhiteList: [], // referer white list
214
+ supportedRequests: [
215
+ // supported URL path and method, the package will match URL path regex patterns one by one until path matched. We recommend you set {path: /^\//, methods:['POST','PATCH','DELETE','PUT','CONNECT']} as the last rule in the list, which is also the default config.
216
+ { path: /^\//, methods: ['POST', 'PATCH', 'DELETE', 'PUT', 'CONNECT'] },
222
217
  ],
223
- cookieOptions: {}, // csrf token's cookie options
218
+ cookieOptions: {}, // csrf token's cookie options
224
219
  },
225
- }
220
+ };
226
221
  ```
227
222
 
228
223
  `methods` in `supportedRequests` can be empty, which means if you set `supportedRequests: [{path: /.*/, methods:[]}]`, the whole csrf protection will be disabled.
@@ -243,7 +238,7 @@ If you need to use `ctx.redirect`, you need to do the following configuration in
243
238
 
244
239
  ```js
245
240
  exports.security = {
246
- domainWhiteList:['.domain.com'], // security whitelist, starts with '.'
241
+ domainWhiteList: ['.domain.com'], // security whitelist, starts with '.'
247
242
  };
248
243
  ```
249
244
 
@@ -256,7 +251,7 @@ Based on [jsonp-body](https://github.com/node-modules/jsonp-body).
256
251
  Defense:
257
252
 
258
253
  - The longest callback function name limit of 50 characters.
259
- - Callback function only allows "[","]","a-zA-Z0123456789_", "$" "." to prevent `xss` or `utf-7` attack.
254
+ - Callback function only allows "[","]","a-zA-Z0123456789\_", "$" "." to prevent `xss` or `utf-7` attack.
260
255
 
261
256
  Config:
262
257
 
@@ -283,7 +278,7 @@ url filter.
283
278
 
284
279
  Used for url in html tags (like `<a href=""/><img src=""/>`),please do not call under other places.
285
280
 
286
- `helper.surl($value)`。
281
+ `helper.surl($value)`。
287
282
 
288
283
  **Mention: Particular attention, if you need to resolve URL use `surl`,`surl` need warpped in quotes, Otherwise will lead to XSS vulnerability.**
289
284
 
@@ -321,7 +316,7 @@ So if you want `surl` support custom protocol, please extend the security `proto
321
316
 
322
317
  ```js
323
318
  exports.security = {
324
- protocolWhitelist: ['test']
319
+ protocolWhitelist: ['test'],
325
320
  };
326
321
  ```
327
322
 
@@ -356,10 +351,8 @@ const value = `<a href="http://www.domain.com">google</a><script>evilcode…</sc
356
351
 
357
352
  // in your view
358
353
  <html>
359
- <body>
360
- ${helper.shtml($value)}
361
- </body>
362
- </html>
354
+ <body>${helper.shtml($value)}</body>
355
+ </html>;
363
356
  // => <a href="http://www.domain.com">google</a>&lt;script&gt;evilcode…&lt;/script&gt;
364
357
  ```
365
358
 
@@ -371,7 +364,9 @@ shtml based on [xss](https://github.com/leizongmin/js-xss/), and add filter by d
371
364
  For example, only support `a` tag, and filter all attributes except for `title`:
372
365
 
373
366
  ```javascript
374
- whiteList: {a: ['title']}
367
+ whiteList: {
368
+ a: ['title'];
369
+ }
375
370
  ```
376
371
 
377
372
  options:
@@ -423,14 +418,12 @@ If you want to output json in javascript without encoding, it will be a risk for
423
418
  sjson supports json encode,it will iterate all keys in json, then escape all characters in the value to `\x` to avoid XSS attack, and keep the json structure unchanged.
424
419
  If you want to output json string in your views, please use `${ctx.helper.sjson(var)}`to escape.
425
420
 
426
- __it has a very complex process and will lost performance, so avoid the use as far as possible__
421
+ **it has a very complex process and will lost performance, so avoid the use as far as possible**
427
422
 
428
423
  example:
429
424
 
430
425
  ```js
431
- <script>
432
- window.locals = ${ctx.helper.sjson(locals)};
433
- </script>
426
+ <script>window.locals = ${ctx.helper.sjson(locals)};</script>
434
427
  ```
435
428
 
436
429
  ### .cliFilter()
@@ -442,17 +435,13 @@ If you want to get user submit for command's parameter, please use `cliFilter`
442
435
  before fix:
443
436
 
444
437
  ```js
445
-
446
- cp.exec("bash /home/admin/ali-knowledge-graph-backend/initrun.sh " + port);
447
-
438
+ cp.exec('bash /home/admin/ali-knowledge-graph-backend/initrun.sh ' + port);
448
439
  ```
449
440
 
450
441
  after fix:
451
442
 
452
443
  ```js
453
-
454
- cp.exec("bash /home/admin/ali-knowledge-graph-backend/initrun.sh " + ctx.helper.cliFilter(port));
455
-
444
+ cp.exec('bash /home/admin/ali-knowledge-graph-backend/initrun.sh ' + ctx.helper.cliFilter(port));
456
445
  ```
457
446
 
458
447
  ### .escapeShellArg()
@@ -460,7 +449,7 @@ after fix:
460
449
  Escape command line arguments. Add single quotes around a string and quotes/escapes any existing single quotes allowing you to pass a string directly to a shell function and having it be treated as a single safe argument.
461
450
 
462
451
  ```js
463
- const ip = '127.0.0.1 && cat /etc/passwd'
452
+ const ip = '127.0.0.1 && cat /etc/passwd';
464
453
  const cmd = 'ping -c 1 ' + this.helper.escapeShellArg(ip);
465
454
 
466
455
  console.log(cmd);
@@ -469,10 +458,10 @@ console.log(cmd);
469
458
 
470
459
  ### .escapeShellCmd()
471
460
 
472
- Command line escape to remove the following characters from the entered command line: ```#&;`|*?~<>^()[]{}$;'", 0x0A and 0xFF```
461
+ Command line escape to remove the following characters from the entered command line: ``#&;`|*?~<>^()[]{}$;'", 0x0A and 0xFF``
473
462
 
474
463
  ```js
475
- const ip = '127.0.0.1 && cat /etc/passwd'
464
+ const ip = '127.0.0.1 && cat /etc/passwd';
476
465
  const cmd = 'ping -c 1 ' + this.helper.escapeShellCmd(ip);
477
466
 
478
467
  console.log(cmd);
@@ -524,7 +513,7 @@ In a [Server-Side Request Forgery (SSRF)](https://www.owasp.org/index.php/Server
524
513
 
525
514
  - ipBlackList(Array) - specific which IP addresses are illegal when requested with `safeCurl`.
526
515
  - ipExceptionList(Array) - specific which IP addresses are legal within ipBlackList.
527
- hostnameExceptionList(Array) - specifies which hostnames are legal within ipBlackList.
516
+ hostnameExceptionList(Array) - specifies which hostnames are legal within ipBlackList.
528
517
  - checkAddress(Function) - determine the ip by the function's return value, `false` means illegal ip.
529
518
 
530
519
  ```js
@@ -532,24 +521,15 @@ hostnameExceptionList(Array) - specifies which hostnames are legal within ipBlac
532
521
  exports.security = {
533
522
  ssrf: {
534
523
  // support both cidr subnet or specific IP
535
- ipBlackList: [
536
- '10.0.0.0/8',
537
- '127.0.0.1',
538
- '0.0.0.0/32',
539
- ],
524
+ ipBlackList: ['10.0.0.0/8', '127.0.0.1', '0.0.0.0/32'],
540
525
  // support both cidr subnet or specific IP
541
- ipExceptionList: [
542
- '10.1.1.1',
543
- '10.10.0.1/24',
544
- ],
526
+ ipExceptionList: ['10.1.1.1', '10.10.0.1/24'],
545
527
  // legal hostname
546
- hostnameExceptionList: [
547
- 'example.com',
548
- ],
528
+ hostnameExceptionList: ['example.com'],
549
529
  // checkAddress has higher priority than ipBlackList
550
530
  checkAddress(ip) {
551
531
  return ip !== '127.0.0.1';
552
- }
532
+ },
553
533
  },
554
534
  };
555
535
  ```
@@ -564,6 +544,6 @@ exports.security = {
564
544
 
565
545
  ## Contributors
566
546
 
567
- [![Contributors](https://contrib.rocks/image?repo=eggjs/security)](https://github.com/eggjs/security/graphs/contributors)
547
+ [![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)
568
548
 
569
549
  Made with [contributors-img](https://contrib.rocks).
package/README.zh-CN.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # @eggjs/security
2
2
 
3
3
  [![NPM version][npm-image]][npm-url]
4
- [![Node.js CI](https://github.com/eggjs/security/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/security/actions/workflows/nodejs.yml)
5
- [![Test coverage][codecov-image]][codecov-url]
6
4
  [![Known Vulnerabilities][snyk-image]][snyk-url]
7
5
  [![npm download][download-image]][download-url]
8
6
  [![Node.js Version](https://img.shields.io/node/v/eggjs/security.svg?style=flat)](https://nodejs.org/en/download/)
@@ -11,8 +9,6 @@
11
9
 
12
10
  [npm-image]: https://img.shields.io/npm/v/@eggjs/security.svg?style=flat-square
13
11
  [npm-url]: https://npmjs.org/package/@eggjs/security
14
- [codecov-image]: https://codecov.io/gh/eggjs/security/branch/master/graph/badge.svg
15
- [codecov-url]: https://codecov.io/gh/eggjs/security
16
12
  [snyk-image]: https://snyk.io/test/npm/@eggjs/security/badge.svg?style=flat-square
17
13
  [snyk-url]: https://snyk.io/test/npm/@eggjs/security
18
14
  [download-image]: https://img.shields.io/npm/dm/@eggjs/security.svg?style=flat-square
@@ -62,7 +58,6 @@ exports.security = {
62
58
  },
63
59
  },
64
60
  };
65
-
66
61
  ```
67
62
 
68
63
  如果需要针对某一路径忽略某安全选项,则配置 ignore 选项,例如针对 `/example` 关闭 xframe,以便合作商户能够嵌入我们的页面:
@@ -77,10 +72,9 @@ exports.security = {
77
72
  // ...
78
73
  },
79
74
  };
80
-
81
75
  ```
82
76
 
83
- __注意:如果存在 match 则忽略 ignore。__
77
+ **注意:如果存在 match 则忽略 ignore。**
84
78
 
85
79
  ## API
86
80
 
@@ -92,9 +86,9 @@ __注意:如果存在 match 则忽略 ignore。__
92
86
 
93
87
  ### csrf
94
88
 
95
- __使用__
89
+ **使用**
96
90
 
97
- * `ctx.csrf` 获取 csrf token
91
+ - `ctx.csrf` 获取 csrf token
98
92
 
99
93
  一般在 POST 表单时使用。
100
94
 
@@ -108,8 +102,7 @@ __使用__
108
102
 
109
103
  ```html
110
104
  <form method="POST" action="/upload?_csrf={{ ctx.csrf | safe }}" enctype="multipart/form-data">
111
- title: <input name="title" />
112
- file: <input name="file" type="file" />
105
+ title: <input name="title" /> file: <input name="file" type="file" />
113
106
  <button type="submit">上传</button>
114
107
  </form>
115
108
  ```
@@ -118,18 +111,18 @@ __使用__
118
111
 
119
112
  ajax 防跨站攻击。
120
113
 
121
- __使用__
114
+ **使用**
122
115
 
123
116
  在 ajax 请求时,以 `ctoken` 为 name 带上 ctoken 即可。
124
117
 
125
118
  ctoken 从 cookie 中获取
126
119
 
127
- __安全开发者约定__
120
+ **安全开发者约定**
128
121
 
129
- * `ctx.ctoken` 获取 ctoken 的逻辑。使用者不要调用,安全插件内部使用。
130
- * `ctx.setCTOKEN()` 设置 ctoken 的逻辑。使用者不要调用,安全插件内部使用。
131
- * `ctx.assertCTOKEN()` ctoken 校验逻辑。使用者不要调用,安全插件内部使用。
132
- * `ctx.setCTOKEN()`会将cookie设置到主域名下,主要考虑主域名下其他子域名对应的应用之间的互相调用。例如 A.xx.com 域种了 ctoken,会设置cookie到xx.com域上,在 B.xx.com 域的时候可以利用 ctoken 去请求,在 A 域 jsonp 请求 B 域的时候,B 域也可以验证 ctoken。
122
+ - `ctx.ctoken` 获取 ctoken 的逻辑。使用者不要调用,安全插件内部使用。
123
+ - `ctx.setCTOKEN()` 设置 ctoken 的逻辑。使用者不要调用,安全插件内部使用。
124
+ - `ctx.assertCTOKEN()` ctoken 校验逻辑。使用者不要调用,安全插件内部使用。
125
+ - `ctx.setCTOKEN()`会将cookie设置到主域名下,主要考虑主域名下其他子域名对应的应用之间的互相调用。例如 A.xx.com 域种了 ctoken,会设置cookie到xx.com域上,在 B.xx.com 域的时候可以利用 ctoken 去请求,在 A 域 jsonp 请求 B 域的时候,B 域也可以验证 ctoken。
133
126
 
134
127
  可拓展实现。例如 ctoken token 存在什么 cookie,存什么字段等,都可以通过以上两个接口拓展。
135
128
 
@@ -138,29 +131,30 @@ __安全开发者约定__
138
131
  ```js
139
132
  exports.security = {
140
133
  csrf: {
141
- type: 'ctoken', // 可以是 ctoken / referer / all, 默认为 ctoken
142
- useSession: false, // 如果设为 true,secret 将存储在 session 中
143
- ignoreJSON: false, // 如果设为 true ,将忽略 json 请求
144
- cookieName: 'csrfToken', // csrf 的 token 在 cookie 中存储的 key 名称
145
- sessionName: 'csrfToken', // csrf 的 token 在 session 中存储的 key 名称
134
+ type: 'ctoken', // 可以是 ctoken / referer / all, 默认为 ctoken
135
+ useSession: false, // 如果设为 true,secret 将存储在 session 中
136
+ ignoreJSON: false, // 如果设为 true ,将忽略 json 请求
137
+ cookieName: 'csrfToken', // csrf 的 token 在 cookie 中存储的 key 名称
138
+ sessionName: 'csrfToken', // csrf 的 token 在 session 中存储的 key 名称
146
139
  headerName: 'x-csrf-token', // csrf token 在 header 中的名称
147
- bodyName: '_csrf', // csrf token 在 body 中的名称
148
- queryName: '_csrf', // csrf token 在 query 中的名称
149
- rotateWhenInvalid: false, // csrf invalid 时刷新 token,用于同域名下多个业务 token 可能互相影响的情况
150
- refererWhiteList: [], // referer 白名单
151
- supportedRequests: [ // 支持的 url path pattern 和方法,根据配置名单由上至下匹配 url path 正则,建议在自定义时配置 {path: /^\//, methods:['POST','PATCH','DELETE','PUT','CONNECT']} 为兜底规则
152
- {path: /^\//, methods:['POST','PATCH','DELETE','PUT','CONNECT']},
140
+ bodyName: '_csrf', // csrf token 在 body 中的名称
141
+ queryName: '_csrf', // csrf token 在 query 中的名称
142
+ rotateWhenInvalid: false, // csrf invalid 时刷新 token,用于同域名下多个业务 token 可能互相影响的情况
143
+ refererWhiteList: [], // referer 白名单
144
+ supportedRequests: [
145
+ // 支持的 url path pattern 和方法,根据配置名单由上至下匹配 url path 正则,建议在自定义时配置 {path: /^\//, methods:['POST','PATCH','DELETE','PUT','CONNECT']} 为兜底规则
146
+ { path: /^\//, methods: ['POST', 'PATCH', 'DELETE', 'PUT', 'CONNECT'] },
153
147
  ],
154
148
  },
155
- }
149
+ };
156
150
  ```
157
151
 
158
152
  注意,methods 可以为空, 如果将 supportedRequests 设置为`supportedRequests: [{path: /^\//, methods:[]}]`, 那么等效于关闭 csrf 防御。
159
153
 
160
154
  ### safe redirect
161
155
 
162
- * `ctx.redirect(url)` 如果不在配置的白名单内,则禁止
163
- * `ctx.unsafeRedirect(url)` 不建议使用
156
+ - `ctx.redirect(url)` 如果不在配置的白名单内,则禁止
157
+ - `ctx.unsafeRedirect(url)` 不建议使用
164
158
 
165
159
  安全方案覆盖了默认的`ctx.redirect`方法,所有的跳转均会经过安全域名的判断。
166
160
 
@@ -168,7 +162,7 @@ exports.security = {
168
162
 
169
163
  ```js
170
164
  exports.security = {
171
- domainWhiteList:['.domain.com'], // 安全白名单,以.开头
165
+ domainWhiteList: ['.domain.com'], // 安全白名单,以.开头
172
166
  };
173
167
  ```
174
168
 
@@ -180,13 +174,13 @@ exports.security = {
180
174
 
181
175
  防御内容:
182
176
 
183
- * callback函数名词最长50个字符限制
184
- * callback函数名只允许"[","]","a-zA-Z0123456789_", "$" ".",防止一般的 xss,utf-7 xss等攻击
177
+ - callback函数名词最长50个字符限制
178
+ - callback函数名只允许"[","]","a-zA-Z0123456789\_", "$" ".",防止一般的 xss,utf-7 xss等攻击
185
179
 
186
180
  可定义配置:
187
181
 
188
- * callback 默认 `_callback`,可以改名
189
- * limit - 函数名 length 限制,默认 50
182
+ - callback 默认 `_callback`,可以改名
183
+ - limit - 函数名 length 限制,默认 50
190
184
 
191
185
  ## helper
192
186
 
@@ -210,7 +204,7 @@ url 过滤。
210
204
 
211
205
  对模板中要输出的变量,加 `helper.surl($value)`。
212
206
 
213
- __特别需要注意的是在需要解析url的地方,surl 外面一定要加上双引号,否则就会导致XSS漏洞。__
207
+ **特别需要注意的是在需要解析url的地方,surl 外面一定要加上双引号,否则就会导致XSS漏洞。**
214
208
 
215
209
  不使用 surl
216
210
 
@@ -268,22 +262,22 @@ const value = `<a href="http://www.domain.com">google</a><script>evilcode…</sc
268
262
 
269
263
  // 模板
270
264
  <html>
271
- <body>
272
- ${helper.shtml($value)}
273
- </body>
274
- </html>
265
+ <body>${helper.shtml($value)}</body>
266
+ </html>;
275
267
  // => <a href="http://www.domain.com">google</a>&lt;script&gt;evilcode…&lt;/script&gt;
276
268
  ```
277
269
 
278
270
  shtml 在 [xss](https://github.com/leizongmin/js-xss/) 模块基础上增加了针对域名的过滤。
279
271
 
280
- * [默认规则](https://github.com/leizongmin/js-xss/blob/master/lib/default.js)
281
- * 自定义过滤项 <http://jsxss.com/zh/options.html>
272
+ - [默认规则](https://github.com/leizongmin/js-xss/blob/master/lib/default.js)
273
+ - 自定义过滤项 <http://jsxss.com/zh/options.html>
282
274
 
283
275
  例如只支持 a 标签,且除了 title 其他属性都过滤掉:
284
276
 
285
277
  ```javascript
286
- whiteList: {a: ['title']}
278
+ whiteList: {
279
+ a: ['title'];
280
+ }
287
281
  ```
288
282
 
289
283
  options:
@@ -315,9 +309,9 @@ ${helper.shtml($html)}
315
309
 
316
310
  不合法的路径包括:
317
311
 
318
- * 使用 `..` 的相对路径
319
- * 使用 `/` 开头的绝对路径
320
- * 以及以上试图通过 url encode 试图绕过校验的结果字符串
312
+ - 使用 `..` 的相对路径
313
+ - 使用 `/` 开头的绝对路径
314
+ - 以及以上试图通过 url encode 试图绕过校验的结果字符串
321
315
 
322
316
  ```js
323
317
  const foo = '/usr/local/bin';
@@ -332,14 +326,12 @@ json转义
332
326
  在js中输出json,若未做转义,易被利用为xss漏洞。提供此宏做json encode,会遍历json中的key,将value的值中,所有非白名单字符转义为\x形式,防止xss攻击。同时保持json结构不变。
333
327
  若你有模板中输出一个json字符串给js应用的场景,请使用 `${this.helper.sjson(变量名)}`进行转义。
334
328
 
335
- __处理过程较复杂,性能损耗较大,尽量避免使用__
329
+ **处理过程较复杂,性能损耗较大,尽量避免使用**
336
330
 
337
331
  实例:
338
332
 
339
333
  ```js
340
- <script>
341
- window.locals = ${this.helper.sjson(locals)};
342
- </script>
334
+ <script>window.locals = ${this.helper.sjson(locals)};</script>
343
335
  ```
344
336
 
345
337
  ### .cliFilter()
@@ -351,17 +343,13 @@ __处理过程较复杂,性能损耗较大,尽量避免使用__
351
343
  修复前:
352
344
 
353
345
  ```js
354
-
355
- cp.exec("bash /home/admin/ali-knowledge-graph-backend/initrun.sh " + port);
356
-
346
+ cp.exec('bash /home/admin/ali-knowledge-graph-backend/initrun.sh ' + port);
357
347
  ```
358
348
 
359
349
  修复后:
360
350
 
361
351
  ```js
362
-
363
- cp.exec("bash /home/admin/ali-knowledge-graph-backend/initrun.sh " + this.helper.cliFilter(port));
364
-
352
+ cp.exec('bash /home/admin/ali-knowledge-graph-backend/initrun.sh ' + this.helper.cliFilter(port));
365
353
  ```
366
354
 
367
355
  如果因为业务需要,需要在参数中添加白名单之外的字符。可以将用户输入按照该字符分割,并使用过滤函数过滤每一段数据。
@@ -373,7 +361,7 @@ __处理过程较复杂,性能损耗较大,尽量避免使用__
373
361
  命令行参数转义。给字符串增加一对单引号并且能引用或者转码任何已经存在的单引号, 这样以确保能够直接将一个字符串传入 shell 函数,并且还是确保安全的。
374
362
 
375
363
  ```js
376
- const ip = '127.0.0.1 && cat /etc/passwd'
364
+ const ip = '127.0.0.1 && cat /etc/passwd';
377
365
  const cmd = 'ping -c 1 ' + this.helper.escapeShellArg(ip);
378
366
 
379
367
  console.log(cmd);
@@ -382,10 +370,10 @@ console.log(cmd);
382
370
 
383
371
  ### .escapeShellCmd()
384
372
 
385
- 命令行转义,从输入的命令行中删除下列字符: ```#&;`|*?~<>^()[]{}$;'", 0x0A 和 0xFF```
373
+ 命令行转义,从输入的命令行中删除下列字符: ``#&;`|*?~<>^()[]{}$;'", 0x0A 和 0xFF``
386
374
 
387
375
  ```js
388
- const ip = '127.0.0.1 && cat /etc/passwd'
376
+ const ip = '127.0.0.1 && cat /etc/passwd';
389
377
  const cmd = 'ping -c 1 ' + this.helper.escapeShellCmd(ip);
390
378
 
391
379
  console.log(cmd);
@@ -398,14 +386,14 @@ console.log(cmd);
398
386
 
399
387
  默认开启,如果是 http 站点,需要关闭
400
388
 
401
- * maxAge 默认一年 `365 * 24 * 3600`
402
- * includeSubdomains 默认 false
389
+ - maxAge 默认一年 `365 * 24 * 3600`
390
+ - includeSubdomains 默认 false
403
391
 
404
392
  ### csp
405
393
 
406
394
  默认关闭。需要开启的话,需要和安全工程师确定开启策略。
407
395
 
408
- * policy 策略
396
+ - policy 策略
409
397
 
410
398
  ### X-Download-Options:noopen
411
399
 
@@ -419,16 +407,16 @@ console.log(cmd);
419
407
 
420
408
  默认 SAMEORIGIN,只允许同域把本页面当作 iframe 嵌入。
421
409
 
422
- * value 默认值 `SAMEORIGIN`
410
+ - value 默认值 `SAMEORIGIN`
423
411
 
424
412
  ### X-XSS-Protection
425
413
 
426
- * close 默认值false,即设置为 `1; mode=block`
414
+ - close 默认值false,即设置为 `1; mode=block`
427
415
 
428
416
  ## 其他
429
417
 
430
- * crossdomain.xml robots.txt 支持,默认都不加,系统可自行加,需要咨询项目安全工程师
431
- * 禁止 trace track 两种类型请求
418
+ - crossdomain.xml robots.txt 支持,默认都不加,系统可自行加,需要咨询项目安全工程师
419
+ - 禁止 trace track 两种类型请求
432
420
 
433
421
  ## License
434
422
 
@@ -436,6 +424,6 @@ console.log(cmd);
436
424
 
437
425
  ## Contributors
438
426
 
439
- [![Contributors](https://contrib.rocks/image?repo=eggjs/security)](https://github.com/eggjs/security/graphs/contributors)
427
+ [![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)
440
428
 
441
429
  Made with [contributors-img](https://contrib.rocks).
@@ -0,0 +1,10 @@
1
+ import { Agent, ILifecycleBoot } from "egg";
2
+
3
+ //#region src/agent.d.ts
4
+ declare class AgentBoot implements ILifecycleBoot {
5
+ private readonly agent;
6
+ constructor(agent: Agent);
7
+ configWillLoad(): Promise<void>;
8
+ }
9
+ //#endregion
10
+ export { AgentBoot as default };
package/dist/agent.js ADDED
@@ -0,0 +1,15 @@
1
+ import { preprocessConfig } from "./lib/utils.js";
2
+
3
+ //#region src/agent.ts
4
+ var AgentBoot = class {
5
+ agent;
6
+ constructor(agent) {
7
+ this.agent = agent;
8
+ }
9
+ async configWillLoad() {
10
+ preprocessConfig(this.agent.config.security);
11
+ }
12
+ };
13
+
14
+ //#endregion
15
+ export { AgentBoot as default };
@@ -0,0 +1,14 @@
1
+ import { HttpClientOptions, HttpClientRequestURL, HttpClientResponse } from "../../lib/extend/safe_curl.js";
2
+ import { Agent } from "egg";
3
+
4
+ //#region src/app/extend/agent.d.ts
5
+ declare class SecurityAgent extends Agent {
6
+ safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
7
+ }
8
+ declare module 'egg' {
9
+ interface Agent {
10
+ safeCurl<T = any>(url: HttpClientRequestURL, options?: HttpClientOptions): Promise<HttpClientResponse<T>>;
11
+ }
12
+ }
13
+ //#endregion
14
+ export { SecurityAgent as default };
@@ -0,0 +1,12 @@
1
+ import { safeCurlForApplication } from "../../lib/extend/safe_curl.js";
2
+ import { Agent } from "egg";
3
+
4
+ //#region src/app/extend/agent.ts
5
+ var SecurityAgent = class extends Agent {
6
+ async safeCurl(url, options) {
7
+ return await safeCurlForApplication(this, url, options);
8
+ }
9
+ };
10
+
11
+ //#endregion
12
+ export { SecurityAgent as default };