mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
* test(java): compare overload resolution with javac in CI * test(conformance): share call resolution reports across tools * test(java): cover the overload conversion matrix with javac (#4057) Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> * test(java): run Java-backed fixtures in dedicated CI shards * test(java): replace handwritten resolution cases with javac comparisons * test(java): compare lambda and receiver fixtures against javac * fix(ci): restore Java test evidence and use locked toolchain commands * test(skills): fail incomplete CLI generation checks (#4056) * test(java): compare method references with javac * fix(java): resolve qualified bases and static wildcard overloads * test(java): preserve declared dollar names in compiler comparisons * fix(java): preserve distinct call targets for colliding type names * fix(conformance): resolve private nested bases and retain overload selections * fix(java): distinguish variadic overloads in the published graph * fix(java): match javac for nested types, imports and initializer calls * Move Java fixture testing out of Vitest and into compiler conformance * Verify Java graph endpoints and leave call selection to javac * Match javac for annotated bases and legal static imports * Resolve nested Java member types and clean up failed conformance fixtures * Preserve qualified Java bases across unrelated static wildcard imports * test(java): run inline source fixtures in compiler conformance * test(conformance): check fetch callers, lexical bindings and cleanup * test(java): move virtual source and text fixtures into conformance * fix(java): resolve imported member types and qualified base collisions * Match javac constructor overloads and preserve Java conformance coverage * Compare recovered Java inheritance with javac in the conformance runner * Run the Java query compilation smoke test in native conformance * Clarify Java conformance expectations and check populated suites * Write javac conformance records as UTF-8 on Windows * Compile the Java conformance tools for SonarCloud analysis * Compare Java method implementation edges with javac * Resolve fixture writers and inherited Java methods in their lexical context * Resolve qualified Java bases through their accessible type members * Match local qualified Java bases and bounded varargs identities to javac * Match Java call resolution to javac across the conformance corpus Preserve generic declaration identity, follow nested call results, and type lambda aliases and enhanced-loop variables in their declaration scopes. Report proven JDK call targets without creating workspace edges. Compare every selected source and binary call against javac and remove the twelve mismatch lists. * Compare Java recovery targets as sets and check empty destination addresses Keep repeated uses of the same declaration equivalent across graph producers while detecting missing and extra targets. Check raw destination addresses and document the source and classpath inputs to the compiler comparison. * Avoid extra native parent walks while capturing Java call facts Index lambda origins by spelling before walking lexical scopes, and only check value shadowing for qualifiers rooted in an identifier. This restores the capture traversal budget for anonymous classes while preserving javac call targets. * Refresh the Java capture fingerprint for corrected fixture comments The module captures include the revised comments and the following declarations move to earlier lines. Both emitters produce the same 4,288 capture groups when given the same fixture revision. * Preserve Java conformance assertions and use trusted fixture paths Use explicit canonical sort orders, require missing evidence to fail assertions, and keep pending query results in the replay cache. Resolve the Git executable independently of the test repository and isolate the Spring workspace per test. * Resolve inherited Java members through the scoped superclass * Reuse validated analyzer build hashes for parser cache identity * Resolve SonarCloud findings in Java resolution and compiler conformance * Align Java compiler tool packages and pin benchmark baselines to the tested merge * Honor wildcard method families and fixture ownership in Java conformance * fix(java): resolve inherited and annotation member types against javac Keep workspace links tied to import declarations and compare Java varargs overloads through comments. Make generated-project selection, method metadata checks and Java fixture ownership explicit in conformance. * fix(java): resolve bounded and imported bases during dispatch Keep the type selected from a qualified heritage clause available during overload resolution. Compare annotated bounds, inherited static imports, and String.valueOf arguments directly with javac. Detect Java fixture paths on either side of a filesystem rename. * Conform Java method visibility and wildcard lambda bounds to javac Compare method access at source positions, recognize CommonJS fixture reads, and preserve diagnostics when native conformance setup fails. * Match javac for qualified member overloads and selective call diagnostics * Track reassigned Java fixture paths at their point of use * Respect Java visibility and Node path semantics in conformance checks * Align Java graph benchmarks with compiler-verified visibility * Record the public Java record accessor in the mixed-provider benchmark * Address remaining Java conformance analysis findings Keep repository import scans sequential, simplify Java header and overload resolution, and reuse Spring conformance measurements. Preserve compiler comparison assertions and emitted fixture contents. * Match javac on nested binary names, null factories and recovered calls Preserve the qualified annotation target in workspace links. Compare valid and invalid arguments separately so an attributed recovery symbol cannot mask a failed invocation. --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
348 lines
11 KiB
TypeScript
348 lines
11 KiB
TypeScript
/**
|
|
* Java taint model (#2261) over real Java CFG and import capture output.
|
|
*/
|
|
|
|
import { createRequire } from 'node:module';
|
|
import type { ParsedImport } from 'gitnexus-shared';
|
|
import assert from 'node:assert/strict';
|
|
import { describe, it } from 'node:test';
|
|
import { createJavaCfgVisitor } from '../../../../../src/core/ingestion/cfg/visitors/java.js';
|
|
import { computeReachingDefs } from '../../../../../src/core/ingestion/cfg/reaching-defs.js';
|
|
import type { FunctionCfg } from '../../../../../src/core/ingestion/cfg/types.js';
|
|
import { emitJavaScopeCaptures } from '../../../../../src/core/ingestion/languages/java/captures.js';
|
|
import { interpretJavaImport } from '../../../../../src/core/ingestion/languages/java/interpret.js';
|
|
import { JAVA_TAINT_MODEL } from '../../../../../src/core/ingestion/taint/java-model.js';
|
|
import { hasTaintSafeSites } from '../../../../../src/core/ingestion/taint/site-safety.js';
|
|
import {
|
|
buildTaintImportIndex,
|
|
matchFunctionSites,
|
|
type FunctionSiteMatches,
|
|
type MatchedSinkCall,
|
|
type MatchedSource,
|
|
} from '../../../../../src/core/ingestion/taint/match.js';
|
|
import { computeTaintFlows } from '../../../../../src/core/ingestion/taint/propagate.js';
|
|
import {
|
|
makeCfgHarness,
|
|
bindingIdx,
|
|
type CfgHarness,
|
|
} from '../../../../../test/helpers/cfg-harness.js';
|
|
|
|
const javaGrammar = createRequire(import.meta.url)('tree-sitter-java') as Parameters<
|
|
typeof makeCfgHarness
|
|
>[0];
|
|
|
|
const java: CfgHarness = makeCfgHarness(javaGrammar, createJavaCfgVisitor(), 'fixture.java');
|
|
|
|
function importsFor(src: string): ParsedImport[] {
|
|
return emitJavaScopeCaptures(src, 'fixture.java')
|
|
.filter((m) => m['@import.statement'] !== undefined)
|
|
.map((m) => interpretJavaImport(m))
|
|
.filter((p): p is ParsedImport => p !== null);
|
|
}
|
|
|
|
function cfgOf(code: string, fnIndex = 0): FunctionCfg {
|
|
const cfg = java.cfgOf(code, fnIndex);
|
|
assert.equal(hasTaintSafeSites(cfg), true);
|
|
return cfg;
|
|
}
|
|
|
|
function matchesOf(code: string, fnIndex = 0): { cfg: FunctionCfg; matches: FunctionSiteMatches } {
|
|
const cfg = cfgOf(code, fnIndex);
|
|
return {
|
|
cfg,
|
|
matches: matchFunctionSites(cfg, JAVA_TAINT_MODEL, buildTaintImportIndex(importsFor(code))),
|
|
};
|
|
}
|
|
|
|
function analyze(code: string, fnIndex = 0) {
|
|
const { cfg, matches } = matchesOf(code, fnIndex);
|
|
const defUse = computeReachingDefs(cfg);
|
|
return { cfg, matches, flows: computeTaintFlows(cfg, defUse, matches) };
|
|
}
|
|
|
|
const allSources = (m: FunctionSiteMatches): MatchedSource[] =>
|
|
m.statements.flatMap((s) => [...s.sources]);
|
|
const allSinks = (m: FunctionSiteMatches): MatchedSinkCall[] =>
|
|
m.statements.flatMap((s) => [...s.sinks]);
|
|
|
|
function matchedSinkSite(cfg: FunctionCfg, matches: FunctionSiteMatches, sink: MatchedSinkCall) {
|
|
const sinkSite = matches.statements
|
|
.flatMap((stmt) => stmt.sinks.map((matched) => ({ stmt, matched })))
|
|
.find(({ matched }) => matched === sink);
|
|
assert(sinkSite !== undefined, 'expected matched sink site');
|
|
const site =
|
|
cfg.blocks[sinkSite.stmt.blockIndex].statements?.[sinkSite.stmt.statementIndex]?.sites?.[
|
|
sink.siteIndex
|
|
];
|
|
assert(site !== undefined, 'expected concrete sink site');
|
|
return site;
|
|
}
|
|
|
|
const wrap = (body: string, imports = ''): string => `${imports}
|
|
class C {
|
|
void f(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletRequest req, Helper helper, String safe) {
|
|
${body}
|
|
}
|
|
}`;
|
|
|
|
describe('Java taint model (#2261)', () => {
|
|
it('matches assigned request call results as remote-input sources', () => {
|
|
const { cfg, matches } = matchesOf(wrap(`String p = request.getParameter("id");`));
|
|
const sources = allSources(matches);
|
|
assert.equal(sources.length, 1);
|
|
assert.equal(sources[0].type, 'call-result');
|
|
assert.equal(sources[0].entry.kind, 'remote-input');
|
|
assert.deepEqual(sources[0].type === 'call-result' ? [...sources[0].resultDefs] : [], [
|
|
bindingIdx(cfg, 'p'),
|
|
]);
|
|
assert.equal(matches.hasSource, true);
|
|
});
|
|
|
|
it('propagates an assigned request source into a static-import-proven file read sink', () => {
|
|
const { cfg, matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getParameter("path");
|
|
readString(of(p));
|
|
`,
|
|
`
|
|
import static java.nio.file.Files.readString;
|
|
import static java.nio.file.Path.of;
|
|
`,
|
|
),
|
|
);
|
|
const p = bindingIdx(cfg, 'p');
|
|
const sink = allSinks(matches)[0];
|
|
assert.equal(sink.entry.name, 'readString');
|
|
const site = matchedSinkSite(cfg, matches, sink);
|
|
assert.equal(site?.callee, 'readString');
|
|
assert.ok(site?.args?.[0]?.some((actual) => actual[0] === p && typeof actual[1] === 'number'));
|
|
assert.equal(flows.status, 'computed');
|
|
assert.equal(flows.findings.length, 1);
|
|
assert.equal(flows.findings[0].sinkKind, 'path-traversal');
|
|
assert.equal(flows.findings[0].source.type, 'call-result');
|
|
});
|
|
|
|
it('propagates regular-import-proven Files.readString into a path-traversal finding', () => {
|
|
const { cfg, matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getParameter("path");
|
|
Files.readString(Path.of(p));
|
|
`,
|
|
`
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
`,
|
|
),
|
|
);
|
|
const p = bindingIdx(cfg, 'p');
|
|
const sinks = allSinks(matches);
|
|
assert.equal(sinks.length, 1);
|
|
assert.equal(sinks[0].entry.kind, 'path-traversal');
|
|
const site = matchedSinkSite(cfg, matches, sinks[0]);
|
|
assert.equal(site.callee, 'Files.readString');
|
|
assert.ok(site.args?.[0]?.some((actual) => actual[0] === p && typeof actual[1] === 'number'));
|
|
assert.equal(flows.findings.length, 1);
|
|
assert.equal(flows.findings[0].sinkKind, 'path-traversal');
|
|
});
|
|
|
|
it('supports getHeader call-result sources', () => {
|
|
const { cfg, matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getHeader("X-Path");
|
|
readString(of(p));
|
|
`,
|
|
`
|
|
import static java.nio.file.Files.readString;
|
|
import static java.nio.file.Path.of;
|
|
`,
|
|
),
|
|
);
|
|
const p = bindingIdx(cfg, 'p');
|
|
const sources = allSources(matches);
|
|
assert.equal(sources.length, 1);
|
|
assert(sources[0].type === 'call-result', 'expected getHeader to be a call-result source');
|
|
assert.equal(sources[0].entry.kind, 'remote-input');
|
|
assert.deepEqual([...sources[0].resultDefs], [p]);
|
|
const sinks = allSinks(matches);
|
|
assert.equal(sinks.length, 1);
|
|
assert.equal(sinks[0].entry.kind, 'path-traversal');
|
|
assert.equal(flows.findings.length, 1);
|
|
assert.equal(flows.findings[0].source.type, 'call-result');
|
|
});
|
|
|
|
it('supports the short req receiver for call-result sources', () => {
|
|
const { cfg, matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = req.getParameter("path");
|
|
readString(of(p));
|
|
`,
|
|
`
|
|
import static java.nio.file.Files.readString;
|
|
import static java.nio.file.Path.of;
|
|
`,
|
|
),
|
|
);
|
|
const p = bindingIdx(cfg, 'p');
|
|
const [source] = allSources(matches);
|
|
assert(source?.type === 'call-result', 'expected req.getParameter source');
|
|
assert.deepEqual([...source.resultDefs], [p]);
|
|
assert.equal(flows.findings.length, 1);
|
|
});
|
|
|
|
it('does not seed an unassigned request call result', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(
|
|
`readString(request.getParameter("path"));`,
|
|
'import static java.nio.file.Files.readString;',
|
|
),
|
|
);
|
|
assert.equal(allSources(matches).length, 0);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not treat unrelated same-named receivers as servlet sources', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = helper.getParameter("path");
|
|
readString(p);
|
|
`,
|
|
'import static java.nio.file.Files.readString;',
|
|
),
|
|
);
|
|
assert.equal(allSources(matches).length, 0);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not report a sink when the tainted value is not in the dangerous argument', () => {
|
|
const { cfg, matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getParameter("path");
|
|
String unused = p;
|
|
readString(of(safe));
|
|
`,
|
|
`
|
|
import static java.nio.file.Files.readString;
|
|
import static java.nio.file.Path.of;
|
|
`,
|
|
),
|
|
);
|
|
const p = bindingIdx(cfg, 'p');
|
|
const sink = allSinks(matches)[0];
|
|
assert.equal(sink.entry.name, 'readString');
|
|
const site = matchedSinkSite(cfg, matches, sink);
|
|
assert.equal(site?.callee, 'readString');
|
|
const sinkArgs = site?.args?.[0];
|
|
assert.ok(sinkArgs, 'expected the sink to record its first argument');
|
|
assert.ok(!sinkArgs.some((actual) => actual[0] === p && typeof actual[1] === 'number'));
|
|
assert.ok(!sinkArgs.includes(p));
|
|
assert.equal(flows.status, 'computed');
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not match same-named readString calls without static import provenance', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(`
|
|
String p = request.getParameter("path");
|
|
readString(p);
|
|
helper.readString(p);
|
|
`),
|
|
);
|
|
assert.equal(allSinks(matches).length, 0);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not report Paths.get or Path.of constructors as sinks', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getParameter("path");
|
|
get(p);
|
|
of(p);
|
|
`,
|
|
`
|
|
import static java.nio.file.Paths.get;
|
|
import static java.nio.file.Path.of;
|
|
`,
|
|
),
|
|
);
|
|
assert.equal(allSinks(matches).length, 0);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not match unrelated static imports named readString', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getParameter("path");
|
|
readString(p);
|
|
`,
|
|
'import static com.example.Files.readString;',
|
|
),
|
|
);
|
|
assert.equal(allSinks(matches).length, 0);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not match unrelated regular imports named Files', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getParameter("path");
|
|
Files.readString(p);
|
|
`,
|
|
'import com.example.Files;',
|
|
),
|
|
);
|
|
assert.equal(allSinks(matches).length, 0);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not let a local Files receiver inherit import provenance', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getParameter("path");
|
|
Helper Files = helper;
|
|
Files.readString(p);
|
|
`,
|
|
'import java.nio.file.Files;',
|
|
),
|
|
);
|
|
assert.equal(allSinks(matches).length, 0);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not report untainted input reaching the file read sink', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(
|
|
`readString(of(safe));`,
|
|
`
|
|
import static java.nio.file.Files.readString;
|
|
import static java.nio.file.Path.of;
|
|
`,
|
|
),
|
|
);
|
|
assert.equal(allSinks(matches).length, 1);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
|
|
it('does not report regular-import path constructors without a file sink', () => {
|
|
const { matches, flows } = analyze(
|
|
wrap(
|
|
`
|
|
String p = request.getParameter("path");
|
|
Path.of(p);
|
|
`,
|
|
'import java.nio.file.Path;',
|
|
),
|
|
);
|
|
assert.equal(allSinks(matches).length, 0);
|
|
assert.equal(flows.findings.length, 0);
|
|
});
|
|
});
|