github-advanced-security[bot] commented on code in PR #826:
URL: 
https://github.com/apache/hugegraph-toolchain/pull/826#discussion_r4311397555


##########
hugegraph-hubble/hubble-fe/src/visualization/hubble/icons.test.ts:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+import {expect, test} from '@jest/globals';
+import {hubbleIconSource} from './icons';
+import {iconNames} from '../../utils/iconNames';
+
+test('every saved icon has a bundled local SVG and aliases resolve to the same 
image', () => {
+    for (const [key, alias] of Object.entries(iconNames)) {
+        const image = hubbleIconSource(key);
+        expect(image?.startsWith('data:image/svg+xml,')).toBe(true);
+        expect(hubbleIconSource(alias)).toBe(image);
+        const svg = decodeURIComponent(image!.split(',')[1]);
+        expect(svg).toContain('xmlns="http://www.w3.org/2000/svg";');
+        expect(svg).toContain('<path');
+        
expect(svg).not.toMatch(/<script|\son[a-z]+=|href=|<foreignObject|https?:\/\/(?!www.w3.org)/i);

Review Comment:
   ## CodeQL / Incomplete regular expression for hostnames
   
   This regular expression has an unescaped '.' before 'w3.org', so it might 
match more hosts than expected.
   
   [Show more 
details](https://github.com/apache/hugegraph-toolchain/security/code-scanning/29)



##########
hugegraph-hubble/hubble-dist/assembly/travis/run_ui_full_acceptance.test.js:
##########
@@ -0,0 +1,291 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+'use strict';
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const os = require('node:os');
+const path = require('node:path');
+const {spawnSync} = require('node:child_process');
+const {options, fixtureFromLiveReport, prepareGraphArgs, run, main, exitCode} 
= require('./run_ui_full_acceptance');
+const {ALL_CHECKS} = require('./run_ui_graph_acceptance');
+
+function config(directory, args = []) {
+  return options(['node', 'wrapper', '--output-dir', directory, ...args],
+    {HUBBLE_USERNAME: 'writer', HUBBLE_PASSWORD: 'private-secret'});
+}
+function liveReport() {
+  return {status: 'passed', hubble_url: 'http://127.0.0.1:8088', graph: 
'hugegraph',
+    graphspace: 'DEFAULT', data_prefix: 'real_123', checks: [
+      {name: 'hubble-login', status: 'passed', user: 'writer'},
+      {name: 'server-loader-rest-count', status: 'passed', vertices: 3, edges: 
2},
+      {name: 'hubble-schema-vertexlabel', status: 'passed', label: 
'real_123_person', created: true},
+      {name: 'hubble-schema-edgelabel', status: 'passed', label: 
'real_123_knows', created: true}
+    ]};
+}
+function directory(t) {
+  const output = fs.mkdtempSync(path.join(os.tmpdir(), 
'hubble-ui-wrapper-test-'));
+  t.after(() => fs.rmSync(output, {recursive: true, force: true}));
+  return output;
+}
+function childRunner(status = 'passed', code = 0, observe = () => {}) {
+  return (command, args, settings) => {
+    observe(command, args, settings);
+    const graph = args[0].endsWith('run_ui_graph_acceptance.js');
+    const report = args[args.indexOf('--json-output') + 1];
+    const requested = graph ? args[args.indexOf('--checks') + 1].split(',') : 
[];
+    fs.writeFileSync(report, JSON.stringify({status: graph ? status : 'passed',
+      ...(graph ? {requestedChecks: requested, checks: requested.map(name => 
({name, status})),
+        fullRequestedMatrix: status === 'passed' && ALL_CHECKS.every(name => 
requested.includes(name)),
+        remainingMatrix: ['Separate real auth-mode matrix']} : {})}));
+    return {status: graph ? code : 0, stdout: 'private-secret', stderr: ''};
+  };
+}
+
+test('default wrapper requires every real graph check, with only explicit 
subset selection', () => {
+  assert.deepEqual(config('/tmp/output').graphChecks, ALL_CHECKS);
+  assert.deepEqual(config('/tmp/output', ['--graph-checks', 
'example,query']).graphChecks, ['example', 'query']);
+  assert.throws(() => config('/tmp/output', ['--graph-checks', '']), 
/Unknown/);
+  assert.throws(() => config('/tmp/output', ['--graph-checks', 'typo']), 
/Unknown/);
+});
+
+test('fixture permission comes from exact successful schema writes, never 
generic passed/conflict checks', () => {
+  const cfg = config('/tmp/output');
+  assert.equal(fixtureFromLiveReport(liveReport(), cfg).canWriteSchema, true);
+  for (const value of [false, undefined]) {
+    const report = liveReport();
+    report.checks[2].created = value;
+    assert.equal(fixtureFromLiveReport(report, cfg).canWriteSchema, undefined);
+  }
+  const report = liveReport();
+  report.checks[3].label = 'unrelated';
+  assert.equal(fixtureFromLiveReport(report, cfg).canWriteSchema, undefined);
+});
+
+test('live fixture rejects wrong server, graph, GraphSpace, actor and missing 
real Loader proof', () => {
+  for (const mutate of [
+    value => {value.hubble_url = 'http://different:8088';},
+    value => {value.graph = 'other';}, value => {delete value.graphspace;},
+    value => {value.checks[0].user = 'another';}, value => 
{value.checks[1].vertices = 0;},
+    value => {value.status = 'failed';}
+  ]) {
+    const report = liveReport(); mutate(report);
+    assert.throws(() => fixtureFromLiveReport(report, config('/tmp/output')), 
{name: 'NeedsInput'});
+  }
+});
+
+test('wrapper always runs graph gate, carries missing-input exit 2 and never 
writes credentials', t => {
+  const cfg = config(directory(t));
+  const calls = [];
+  const report = main(cfg, childRunner('needs input', 2, (command, args, 
settings) => {
+    calls.push(args[0]);
+    assert.ok(!args.includes(cfg.password));
+    assert.equal(settings.env.HUBBLE_PASSWORD, cfg.password);
+  }));
+  assert.equal(calls.length, 3);
+  assert.ok(calls[2].endsWith('run_ui_graph_acceptance.js'));
+  assert.equal(report.status, 'needs input');
+  assert.equal(exitCode(report.status), 2);
+  assert.equal(report.fullRequestedMatrix, false);
+  assert.ok(!fs.readFileSync(cfg.jsonOutput, 'utf8').includes(cfg.password));
+});
+
+test('explicit standalone subset stays a subset in aggregate even when every 
requested child passes', t => {
+  const cfg = config(directory(t), ['--graph-checks', 
'example,authentication,query,schema,cards,algorithm']);
+  const liveFile = path.join(cfg.outputDir, 'live.json');
+  fs.writeFileSync(liveFile, JSON.stringify(liveReport())); cfg.liveReport = 
liveFile;
+  const report = main(cfg, childRunner());
+  assert.equal(report.status, 'passed');
+  assert.equal(report.fullRequestedMatrix, false);
+  const fixture = JSON.parse(fs.readFileSync(path.join(cfg.outputDir, 
'graph-fixture.json'), 'utf8'));
+  assert.equal(fixture.canWriteSchema, true);
+  assert.deepEqual(fixture.expected.vertexIds, ['real_123_alice', 
'real_123_bob', 'real_123_carol']);
+  assert.equal(fixture.graphspace, 'DEFAULT');
+  assert.deepEqual(report.checks[2].remainingMatrix, ['Separate real auth-mode 
matrix']);
+});
+
+test('failed or inconsistent child cannot pass using a stale report or a 
nominal zero exit', t => {
+  const cfg = config(directory(t)), file = path.join(cfg.outputDir, 
'child.json');
+  fs.writeFileSync(file, '{"status":"passed"}');
+  const missing = run('child', [], file, cfg, () => ({status: 0, stdout: '', 
stderr: ''}));
+  assert.equal(missing.status, 'failed');
+  const signaled = run('child', [], file, cfg, () => ({status: null, signal: 
'SIGTERM'}));
+  assert.equal(signaled.status, 'failed');
+  assert.equal(signaled.signal, 'SIGTERM');
+  const report = main(cfg, childRunner('failed', 0));
+  assert.equal(report.status, 'failed');
+  assert.equal(exitCode(report.status), 1);
+});
+
+test('unusable live report is recorded as a graph missing-input failure 
without a green skip', t => {
+  const cfg = config(directory(t));
+  cfg.liveReport = path.join(cfg.outputDir, 'live.json');
+  fs.writeFileSync(cfg.liveReport, JSON.stringify({...liveReport(), graph: 
'wrong'}));
+  const report = main(cfg, childRunner());
+  assert.equal(report.checks.length, 3);
+  assert.equal(report.checks[2].name, 'ui-graph-acceptance');
+  assert.equal(report.status, 'needs input');
+});
+
+// Exercise the actual shell orchestration with fixture commands, never a 
service/browser.
+test('distribution wrapper preserves needs-input manifest and exit 2 across 
cleanup', t => {
+  const output = directory(t), evidence = path.join(output, 'evidence');
+  fs.mkdirSync(evidence);
+  fs.writeFileSync(path.join(evidence, 'manifest.json'), 
'{"status":"passed"}');
+  const tarball = path.join(output, 'candidate.tar.gz'); 
fs.writeFileSync(tarball, 'test-only');
+  const fixtureCommand = path.join(output, 'fixture-command');
+  const invocationFile = path.join(output, 'invocations.jsonl');
+  fs.writeFileSync(fixtureCommand, `#!/usr/bin/env node
+const fs = require('node:fs'), path = require('node:path'), cp = 
require('node:child_process');
+const args = process.argv.slice(2);
+if (args.includes('--validate-urls')) {
+  const result = cp.spawnSync('python3', args, {stdio: 'inherit'});
+  process.exit(result.status);
+}
+if (args[0] === '-') {
+  const result = cp.spawnSync(process.execPath, args, {stdio: 'inherit'});
+  process.exit(result.status);
+}
+fs.appendFileSync(process.env.TEST_INVOCATIONS, JSON.stringify(args) + '\\n');
+if (process.env.HUBBLE_PASSWORD !== 'private-secret') process.exit(99);
+const file = args[args.indexOf('--json-output') + 1];
+const ui = args[0].endsWith('run_ui_full_acceptance.js');
+if (process.env.HUBBLE_URL !== 'https://example.invalid/deploy/hubble') 
process.exit(98);
+if (!ui && process.env.HUBBLE_SMOKE_SERVER_URL !== 
'https://example.invalid/deploy/server') process.exit(98);
+fs.mkdirSync(path.dirname(file), {recursive: true});
+fs.writeFileSync(file, JSON.stringify(ui ? {status: 'needs input', 
fullRequestedMatrix: false,
+  graphRequestedChecks: ['example', 'scope']} : {status: 'passed', hubble_url: 
process.env.HUBBLE_URL,
+  server_url: process.env.HUBBLE_SMOKE_SERVER_URL, graph: 'g', graphspace: 
'DEFAULT'}));
+process.exit(ui ? 2 : 0);
+`, {mode: 0o755});
+  const result = spawnSync('bash', [path.join(__dirname, 
'verify-hubble-issue-694.sh'), tarball,
+    'https://example.invalid/deploy/server'], {
+    encoding: 'utf8', env: {...process.env, PYTHON: fixtureCommand, NODE: 
fixtureCommand,
+      HUBBLE_USERNAME: 'writer', HUBBLE_PASSWORD: 'private-secret',
+      HUBBLE_URL: 'https://example.invalid/deploy/hubble',
+      HUBBLE_694_EVIDENCE_DIR: evidence, TEST_INVOCATIONS: invocationFile}
+  });
+  assert.equal(result.status, 2, result.stderr);
+  const manifest = JSON.parse(fs.readFileSync(path.join(evidence, 
'manifest.json'), 'utf8'));
+  assert.equal(manifest.status, 'needs input');
+  assert.equal(manifest.fullRequestedMatrix, false);
+  assert.equal(manifest.hubbleUrl, 'https://example.invalid/deploy/hubble');
+  assert.equal(manifest.serverUrl, 'https://example.invalid/deploy/server');
+  assert.deepEqual(manifest.graphRequestedChecks, ['example', 'scope']);
+  assert.ok(!result.stdout.includes('checks passed'));
+  assert.ok(!fs.readFileSync(invocationFile, 
'utf8').includes('private-secret'));
+  assert.ok(!fs.readFileSync(invocationFile, 
'utf8').includes('https://example.invalid/'));

Review Comment:
   ## CodeQL / Incomplete URL substring sanitization
   
   '[https://example.invalid/](1)' can be anywhere in the URL, and arbitrary 
hosts may come before or after it.
   
   [Show more 
details](https://github.com/apache/hugegraph-toolchain/security/code-scanning/28)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to