@qvac/harness 1.0.0 → 1.0.1

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/CHANGELOG.md CHANGED
@@ -1495,6 +1495,11 @@ breaking change is listed under Changed and Removed.
1495
1495
 
1496
1496
  ### Fixed
1497
1497
 
1498
+ - A bad TLS certificate stops a run instead of being worked around. `web_fetch` and
1499
+ `http_request` answer a certificate failure with code `tls` and a message that names the host
1500
+ and the OpenSSL reason and tells the model not to retry or bypass verification, on Node and on
1501
+ Bare. `exec` refuses `curl -k`, `--insecure`, `wget --no-check-certificate` and
1502
+ `NODE_TLS_REJECT_UNAUTHORIZED=0`, also through `env`.
1498
1503
  - A run on a remote model host no longer stays busy after its answer arrived. The
1499
1504
  completion frame's unused `byteLength` field decoded as 0 on every frame, and
1500
1505
  streamx read that as the frame's size, so when two frames reached the harness
@@ -15,3 +15,5 @@ export declare function shellDownloader(command: string): string | null;
15
15
  export declare const SHELL_DOWNLOAD_NOTE = "The file was saved on this device's disk, not in the chat, so the user cannot see it.";
16
16
  export declare function savesDownload(command: string): boolean;
17
17
  export declare function shellOnlyError(command: string): string | null;
18
+ export declare const TLS_BYPASS_ERROR = "This command disables TLS certificate verification. Do not retry and do not bypass certificate checks; tell the user the site's certificate is invalid.";
19
+ export declare function tlsBypassError(command: string): string | null;
@@ -107,3 +107,32 @@ export function shellOnlyError(command) {
107
107
  }
108
108
  return runsInterpreter(command) ? PYTHON_UNAVAILABLE_ERROR : null;
109
109
  }
110
+ export const TLS_BYPASS_ERROR = "This command disables TLS certificate verification. Do not retry and do not bypass certificate checks; tell the user the site's certificate is invalid.";
111
+ function curlInsecure(words) {
112
+ for (let i = 1; i < words.length; i++) {
113
+ const word = words[i] ?? '';
114
+ if (word === '--insecure') {
115
+ return true;
116
+ }
117
+ const flags = /^-[A-Za-z]/.test(word) ? word.slice(1) : '';
118
+ const valued = [...flags].findIndex((flag) => CURL_VALUED.has(flag));
119
+ const own = valued === -1 ? flags : flags.slice(0, valued);
120
+ if (own.includes('k')) {
121
+ return true;
122
+ }
123
+ i += valued !== -1 && valued === flags.length - 1 ? 1 : 0;
124
+ }
125
+ return false;
126
+ }
127
+ export function tlsBypassError(command) {
128
+ const first = ShellLine.parse(command).commands[0];
129
+ if (!first) {
130
+ return null;
131
+ }
132
+ const bin = commandBin(command);
133
+ const assignments = bin === 'env' ? [...first.assignments, ...first.argv] : first.assignments;
134
+ const bypass = assignments.some((each) => each === 'NODE_TLS_REJECT_UNAUTHORIZED=0') ||
135
+ (bin === 'curl' && curlInsecure(first.argv)) ||
136
+ (bin === 'wget' && first.argv.some((each) => each.startsWith('--no-check-cert')));
137
+ return bypass ? TLS_BYPASS_ERROR : null;
138
+ }
@@ -5,7 +5,7 @@ import { createShellAdapter } from './exec/adapters/shell/shell-adapter.js';
5
5
  import { isPythonLanguage } from './exec/python-source.js';
6
6
  import { MAX_OUTPUT_CHARS, MAX_OUTPUT_CHARS_LIMIT } from './exec/runner.js';
7
7
  import { bareBin, sanitizeCommand } from './exec/scope.js';
8
- import { LANGUAGE_UNAVAILABLE_ERROR, PYTHON_UNAVAILABLE_ERROR, SHELL_DOWNLOAD_NOTE, shellOnlyError, videoToolError } from './exec/shell-guidance.js';
8
+ import { LANGUAGE_UNAVAILABLE_ERROR, PYTHON_UNAVAILABLE_ERROR, SHELL_DOWNLOAD_NOTE, shellOnlyError, tlsBypassError, videoToolError } from './exec/shell-guidance.js';
9
9
  import { ShellLine } from './exec/shell-line.js';
10
10
  import { bareRuntime } from './exec/bare-runtime.js';
11
11
  import { canonicalDenyRoots, defaultRealpath, hostPath, resolveKey } from './fs/scope.js';
@@ -133,6 +133,7 @@ function checkExecutionScope(args, language, { toolOps, sandbox, languages }) {
133
133
  network: languages.some((each) => each.online({ sandbox }))
134
134
  });
135
135
  return (video ??
136
+ tlsBypassError(command) ??
136
137
  firstAnswer(languages, (each) => each.redirect(args, { sandbox })) ??
137
138
  shellOnlyError(command) ??
138
139
  checkShellScope(command, toolOps));
@@ -12,6 +12,7 @@ import { recordCredentialHealth } from './skills/credential-health.js';
12
12
  import { Policy } from '../policy/index.js';
13
13
  import { attachFetchedFile, attachTextFile, bareMime, dispositionFileName, isFileMime, MAX_FILE_BYTES } from './attachments/fetched-file.js';
14
14
  import { resolveOutboundUrl } from './url-guard.js';
15
+ import { tlsFailure } from './tls-failure.js';
15
16
  const MAX_REDIRECTS = 5;
16
17
  export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credentialStore, credentialAllowList, resolveHost = lookupHost } = {}) {
17
18
  return {
@@ -265,6 +266,10 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
265
266
  if (timedOut || error.name === 'TimeoutError') {
266
267
  return { error: 'request timed out', code: 'timeout' };
267
268
  }
269
+ const tls = tlsFailure(err, url.hostname);
270
+ if (tls) {
271
+ return { error: tls, code: 'tls' };
272
+ }
268
273
  return { error: `request failed: ${error.message}`, code: 'transport' };
269
274
  }
270
275
  finally {
@@ -0,0 +1 @@
1
+ export declare function tlsFailure(err: unknown, host: string): string | null;
@@ -0,0 +1,8 @@
1
+ import { errorCode } from '../guards.js';
2
+ const TLS_CODE = /^(UNABLE_TO_VERIFY_LEAF_SIGNATURE|CERT_HAS_EXPIRED|CERT_NOT_YET_VALID|DEPTH_ZERO_SELF_SIGNED_CERT|SELF_SIGNED_CERT_IN_CHAIN|ERR_TLS_CERT_ALTNAME_INVALID|UNABLE_TO_GET_ISSUER_CERT(_LOCALLY)?|CERT_UNTRUSTED|HOSTNAME_MISMATCH|CERTIFICATE_VERIFY_FAILED)$/;
3
+ export function tlsFailure(err, host) {
4
+ const code = errorCode(err);
5
+ return code && TLS_CODE.test(code)
6
+ ? `The TLS certificate of ${host} could not be verified (${code}). Do not retry and do not bypass certificate checks; tell the user the site's certificate is invalid.`
7
+ : null;
8
+ }
@@ -8,6 +8,7 @@ import { extractEmbeddedState } from '../web-fetch/embedded-state.js';
8
8
  import { extractPageText, looksLikeHtml } from '../web-fetch/extract.js';
9
9
  import { imageFileName, pageImageUrls } from '../web-fetch/images.js';
10
10
  import { pageVideoRef } from '../web-fetch/video.js';
11
+ import { tlsFailure } from './tls-failure.js';
11
12
  import { isRedirectStatus } from './http-request/request.js';
12
13
  import { Policy } from '../policy/index.js';
13
14
  import { attachFetchedFile, attachTextFile, bareMime, fetchedFileName, isFileMime, MAX_FILE_BYTES } from './attachments/fetched-file.js';
@@ -193,6 +194,10 @@ export function createWebFetchTool({ fetch: fetchImpl, resolveHost = lookupHost
193
194
  if (err instanceof Error && err.name === 'TimeoutError') {
194
195
  return { error: `${url.hostname} sent nothing for ${IDLE_TIMEOUT_MS}ms`, code: 'timeout' };
195
196
  }
197
+ const tls = tlsFailure(err, url.hostname);
198
+ if (tls) {
199
+ return { error: tls, code: 'tls' };
200
+ }
196
201
  return { error: errorMessage(err), code: 'transport' };
197
202
  }
198
203
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/harness",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "bare": ">=1.33.4",