Repository navigation
Conversation
Luqmansonar
left a comment
There was a problem hiding this comment.
Two test gaps before this matches the acceptance criteria.
- Packaged npm import
IdentifierUrlsExporterTest checks toJson() and main(), but nothing opens the assembled npm package. The acceptance criteria also require that a Node consumer can import the packaged identifier-urls.json.
npm.xml and package.json files both list that file, and CI uploads sonar-analyzer-commons-configurations-*-npm.tar.gz. A wrong assembly entry would still leave these tests green.
Please add a check that unpacks package/identifier-urls.json from that tarball and imports it the way the README shows:
import identifierUrls from '@sonarsource/analyzer-commons-configurations/identifier-urls.json' with { type: 'json' };
Assert 50 entries and that the strings match CleartextProtocolFilter.exportIdentifierUrls(), including www.topografix.com -> ^/GPX.
- Identifier URL cases
Two representative positives from the shared SonarJS suite are missing, and the whitespace/backslash rules now documented in the npm README are not locked in CleartextProtocolFilterTest.
Please add these positives:
http://neverssl.com/http://osmand.net?mode=extensions#schema— this is the case that requires prepending/before?or#on a^/domain" http://www.w3.org/2000/svg "—isKnownIdentifierstrips surrounding whitespace before matching
And these negatives:
http://www.w3.org/2000/svg extra(internal whitespace)- a backslash in the path, for example
http://www.w3.org/2000\svg
Java already rejects the last two. A test should keep that aligned with the consumer contract in the README.
5441e36 to
c0c18f9
Compare
|
|
|
||
| // JS-2698: exact authorities and case-sensitive path + query + fragment patterns. | ||
| // Matching an identifier is separate from deciding whether an actual connection is safe. | ||
| private static final Map<String, Pattern> IDENTIFIER_URLS = Map.of(); |
There was a problem hiding this comment.
💡 Quality: Identifier matching semantics are now dead code with no tests
With IDENTIFIER_URLS = Map.of(), the lookup at line 246 always returns null, so the suffix normalisation and case-sensitive find() at lines 247-252 never run. This delta also deleted the tests that covered them: exact authority with port, the empty-suffix /, the / prefix for ?/#, and case-sensitive paths. The only test left checks one negative lookup. The javadoc (lines 238-239) and the npm README (lines 29-39) still promise these semantics to non-JVM consumers, but nothing checks them. A regression would only show up once the inventory is filled in, and it would spread to SonarJS through the exported JSON. To fix this, add a package-private overload isKnownIdentifier(String url, Map<String, Pattern> inventory) that the public method calls, and bring back the semantic tests against a test-only map such as example.invalid -> ^/schema.
Make the matcher testable independently of the (currently empty) production inventory.:
public static boolean isKnownIdentifier(String url) {
return isKnownIdentifier(url, IDENTIFIER_URLS);
}
static boolean isKnownIdentifier(String url, Map<String, Pattern> inventory) {
var matcher = IDENTIFIER_URL.matcher(url.strip());
if (!matcher.matches()) {
return false;
}
var pattern = inventory.get(matcher.group(1).toLowerCase(Locale.ROOT));
var remainder = matcher.group(2);
var suffix = remainder == null ? "/" : remainder;
if (!suffix.startsWith("/")) {
suffix = "/" + suffix;
}
return pattern != null && pattern.matcher(suffix).find();
}
Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 2 closed / 3 findings🟡 Medium risk · The new identifier-URL API and npm artifact create a consumer-facing matching contract; semantic mismatches could incorrectly suppress or retain analyzer findings. Adds 💡 Quality: Identifier matching semantics are now dead code with no tests📄 commons/src/main/java/org/sonarsource/analyzer/commons/appsec/CleartextProtocolFilter.java:228 📄 commons/src/main/java/org/sonarsource/analyzer/commons/appsec/CleartextProtocolFilter.java:238-252 📄 commons/src/test/java/org/sonarsource/analyzer/commons/appsec/CleartextProtocolFilterTest.java:30-34 📄 sonar-analyzer-commons-configurations/src/main/packaging/npm/README.md:29-39 With Make the matcher testable independently of the (currently empty) production inventory.✅ 2 closed✅ Quality: npm README omits Java matcher's whitespace/backslash rejection rules
✅ Cross-PR: Whitespace-padded identifier URLs match in Java but not in SonarJS
🤖 Prompt for agentsVerification Rules 1/1 met Knowledge ✅ 1 Repos 2 inspected · PRs 1 inspectedFunctional validation No results Rules 1 passed 2 not applicable
Broader impact Repos 2 inspected PRs 1 inspectedCross-repo 2 repositories inspected 0 open impacts
Cross-PR 1 PR inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |


Summary by Gitar
CleartextProtocolFilter.isKnownIdentifierandexportIdentifierUrlsbacked by an currently empty inventoryIdentifierUrlsExporterto writeidentifier-urls.jsonduringprepare-packageand packaged it in the npm assemblyidentifier-urls.jsonin the npm READMEThis will update automatically on new commits.