@lensmcp/core 1.25.77 → 1.25.79
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/redact.js +1 -1
- package/package.json +2 -2
package/lib/redact.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var f=(e,t)=>v(e,"name",{value:t,configurable:!0});var R=Object.defineProperty,l=f((e,t)=>R(e,"name",{value:t,configurable:!0}),"a");export const REDACTED="REDACTED",MAX_TITLE_CHARS=300,MAX_MESSAGE_CHARS=4096,MAX_URL_CHARS=1024;const O=["token","secret","password","passwd","apikey","credential","assertion","signature"],Z=new Set(["key","auth","authorization","jwt","code","sig","pwd","pass","session","sid","bearer","otp","cookie","set-cookie"]),C=/^(?:(?:prompt|completion|total|input|output|cache|cached|cacheread|cachewrite|reasoning|thinking|max|min|remaining|used|billed)tokens|tokens?(?:count|used|limit|remaining))$/;export function isSecretParam(e){const t=d.get(e);if(t!==void 0)return t;const r=m(e);return e.length<=64&&d.size<N&&d.set(e,r),r}f(isSecretParam,"isSecretParam"),l(isSecretParam,"isSecretParam");const P=new Set(["sess","csrf","xsrf","refresh","nonce","reset","magic","mfa","2fa","verify","verification","invite","login"]);export function isSecretCacheKey(e){for(const t of e.split(/[:/{}#]+/))if(!(!t||t.length>64)){if(isSecretParam(t))return!0;for(const r of t.toLowerCase().split(/[-_.]+/))if(P.has(r))return!0}return!1}f(isSecretCacheKey,"isSecretCacheKey"),l(isSecretCacheKey,"isSecretCacheKey");const N=4096,d=new Map;function m(e){const t=e.toLowerCase();if(C.test(t.replace(/[-_.]+/g,"")))return!1;if(O.some(r=>t.includes(r)))return!0;for(const r of t.split(/[-_.]+/))if(r&&Z.has(r))return!0;return!1}f(m,"$"),l(m,"judgeParam");const D=/^([a-z][a-z0-9+.-]*:\/\/)[^/?#@\s]*@/i,M=/([?&#])([^=&#\s]+)=([^&#\s]*)/g;export function redactUrlParams(e){return e&&e.replace(D,`$1${REDACTED}@`).replace(M,(t,r,n)=>isSecretParam(n)?`${r}${n}=${REDACTED}`:t)}f(redactUrlParams,"redactUrlParams"),l(redactUrlParams,"redactUrlParams");export function redactUrl(e){return e&&clip(redactUrlParams(e),1024)}f(redactUrl,"redactUrl"),l(redactUrl,"redactUrl");const j=/[A-Za-z0-9_.-]{15,}/g;function S(e){for(let t=0;;){const r=e.indexOf("eyJ",t);if(r===-1||e.length-r-3<6)return-1;if(r===0||e.charCodeAt(r-1)===45)return r;t=r+1}}f(S,"D"),l(S,"jwtStart");function w(e){if(e.indexOf("eyJ")===-1||e.indexOf(".")===-1)return e;const t=e.split(".");let r="";for(let n=0;n<t.length;n++){const o=t[n];if(n+2<t.length&&t[n+1].length>=4){const i=S(o);if(i!==-1){r+=o.slice(0,i)+REDACTED,n+=2,n<t.length-1&&(r+=".");continue}}r+=o,n<t.length-1&&(r+=".")}return r}f(w,"x"),l(w,"redactJwtRun");const K=/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]{8,}/gi,L=/\b(authorization|x-api-key|api-key|cookie|set-cookie|proxy-authorization)\b(\s*[:=]\s*)(["']?)((?:(?:bearer|basic)\s+)?[^\s"',;]{4,})\3/gi,U=/[@=:]|eyJ|bearer|basic/i;export function redactText(e){return U.test(e)?redactUrlParams(e).replace(L,(t,r,n,o)=>`${r}${n}${o}${REDACTED}${o}`).replace(j,w).replace(K,(t,r)=>`${r} ${REDACTED}`):e}f(redactText,"redactText"),l(redactText,"redactText");const J=[/\bsk-(?:ant-|proj-|live-|test-)?[A-Za-z0-9_-]{20,}/g,/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,/\bgh[pousr]_[A-Za-z0-9]{30,}/g,/\bxox[abprs]-[A-Za-z0-9-]{10,}/g,/\bAIza[0-9A-Za-z_-]{35}\b/g],h="-----BEGIN ",H=4096;function T(e){if(!e.includes("PRIVATE KEY-----"))return e;let t="",r=0,n=!1;for(;;){const o=e.indexOf(h,r);if(o===-1)break;const i=e.indexOf("-----",o+h.length);if(i===-1)break;const s=e.slice(o+h.length,i);if(!/^[A-Z ]{0,30}PRIVATE KEY$/.test(s)){t+=e.slice(r,i+5),r=i+5;continue}t+=e.slice(r,o);const c=n?-1:e.indexOf("-----END ",i+5);let a;if(c===-1)n=!0,a=Math.min(e.length,i+5+H);else{const u=e.indexOf("-----",c+9);a=u===-1?e.length:u+5}t+=REDACTED,r=a}return t+e.slice(r)}f(T,"U"),l(T,"redactPrivateKeys");const V=/"([A-Za-z0-9_.-]{1,64})"\s*:\s*"((?:[^"\\]|\\.){1,8192})"/g,X=/\b([A-Za-z][A-Za-z0-9_-]{1,40})(\s*[:=]\s*)([^\s"'`,;&)}\]]{8,200})/g,q=/(token|secret|pass(?:word|wd)?|pwd|api[-_]?key|apikey|credential|authorization|bearer)/i;function y(e){return e.replace(V,(t,r)=>isSecretParam(r)?`"${r}": "${REDACTED}"`:t).replace(X,(t,r,n)=>q.test(r)&&isSecretParam(r)?`${r}${n}${REDACTED}`:t)}f(y,"j"),l(y,"redactStructured");export function redactSecretText(e){let t=y(redactText(T(e)));for(const r of J)t=t.replace(r,REDACTED);return t}f(redactSecretText,"redactSecretText"),l(redactSecretText,"redactSecretText");export function clip(e,t){return e.length<=t?e:`${e.slice(0,t)}\u2026[lensmcp truncated: ${e.length-t} more chars]`}f(clip,"clip"),l(clip,"clip");export function safeText(e,t=4096){if(e!==void 0)return clip(redactText(e),t)}f(safeText,"safeText"),l(safeText,"safeText");export function safeTitle(e){return clip(redactText(e),300)}f(safeTitle,"safeTitle"),l(safeTitle,"safeTitle");const G=6,Y=64,B=/^TS\d{1,5}$/,F=l((e,t)=>e==="code"&&typeof t=="string"&&B.test(t),"isDiagnosticCode");export function redactDeep(e,t=0,r=G){if(typeof e=="string")return redactText(e);if(e===null||typeof e!="object"||t>=r)return e;if(Array.isArray(e)){let s;for(let c=0;c<e.length;c++){if(c>=Y){s&&s.push(e[c]);continue}const a=e[c],u=redactDeep(a,t+1,r);s?s.push(u):u!==a&&(s=e.slice(0,c),s.push(u))}return s??e}const n=e,o=Object.keys(n);let i;for(let s=0;s<o.length;s++){const c=o[s],a=n[c],u=isSecretParam(c)&&a!==void 0&&a!==null&&!F(c,a)?REDACTED:redactDeep(a,t+1,r);if(i)i[c]=u;else if(u!==a){i={};for(let p=0;p<s;p++)i[o[p]]=n[o[p]];i[c]=u}}return i??e}f(redactDeep,"redactDeep"),l(redactDeep,"redactDeep");const A=String.raw`(?:"(?:[^"]|"")+"|[A-Za-z_][\w$]*)`,x=String.raw`${A}(?:\s*\.\s*${A})*`,W=String.raw`(?:=|<>|!=|<=|>=|<|>|(?:NOT\s+)?I?LIKE|IS\s+(?:NOT\s+)?DISTINCT\s+FROM)`,Q=new RegExp(String.raw`(${x})\s*${W}\s*(?:[A-Za-z_]\w*\s*\(\s*)?\$(\d+)`,"gi"),ee=new RegExp(String.raw`(${x})\s+(?:NOT\s+)?IN\s*\(([^()]*)\)`,"gi"),te=new RegExp(String.raw`\bINSERT\s+INTO\s+${x}\s*\(([^()]*)\)\s*VALUES\s*`,"gi"),re=new RegExp(A,"g"),k=/\$(\d+)/g,z=16384,ne=256,se=4096,g=new Map,$=l(e=>{const t=e.match(re)??[],r=t[t.length-1]??"";return r.startsWith('"')?r.slice(1,-1).replace(/""/g,'"'):r},"lastIdent");function E(e,t){const r=[];let n=t;for(;;){for(;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]!=="(")return r;const o=[];let i=n+1,s=0,c=!1;for(n+=1;n<e.length;n++){const a=e[n];if(c){a==="'"&&(c=!1);continue}if(a==="'")c=!0;else if(a==="(")s++;else if(a===")"){if(s===0)break;s--}else a===","&&s===0&&(o.push(e.slice(i,n)),i=n+1)}if(n>=e.length)return r;for(o.push(e.slice(i,n)),r.push(o),n+=1;n<e.length&&/\s/.test(e[n]);)n++;if(e[n]!==",")return r;n+=1}}f(E,"et"),l(E,"valuesTuples");function _(e){const t=e.length<=se,r=t?g.get(e):void 0;if(r)return r;const n=e.length>z?e.slice(0,z):e,o=new Set,i=l((s,c)=>{c&&isSecretParam(c)&&o.add(Number(s))},"bind");for(const s of n.matchAll(Q))i(s[2],$(s[1]));for(const s of n.matchAll(ee)){const c=$(s[1]);for(const a of s[2].matchAll(k))i(a[1],c)}for(const s of n.matchAll(te)){const c=s[1].split(",").map(a=>$(a.trim()));for(const a of E(n,(s.index??0)+s[0].length))a.forEach((u,p)=>{const b=c[p];if(b)for(const I of u.matchAll(k))i(I[1],b)})}if(t){if(g.size>=ne){const s=g.keys().next().value;s!==void 0&&g.delete(s)}g.set(e,o)}return o}f(_,"nt"),l(_,"secretPlaceholders");export function redactSqlParams(e,t){if(t.length===0||!e.includes("$"))return t;const r=_(e);if(r.size===0)return t;let n=!1;const o=t.map((i,s)=>i==null||!r.has(s+1)?i:(n=!0,REDACTED));return n?o:t}f(redactSqlParams,"redactSqlParams"),l(redactSqlParams,"redactSqlParams");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/core",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.79",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@lensmcp/protocol-types": "1.25.
|
|
97
|
+
"@lensmcp/protocol-types": "1.25.79",
|
|
98
98
|
"tslib": "^2.3.0"
|
|
99
99
|
},
|
|
100
100
|
"license": "Apache-2.0",
|