Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Map<String, String> getAll(String strongName, Set<String> symbols) {
}

private static final Pattern JsniRefPattern = Pattern.compile("@?([^:]+)::([^(]+)(\\((.*)\\))?");
private static final Pattern fragmentIdPattern = Pattern.compile(".*(\\d+)\\.js");
private static final Pattern fragmentIdPattern = Pattern.compile("(?:.*[^\\d])?(\\d+)\\.js");
Comment thread
zbynek marked this conversation as resolved.
Outdated
// Matches ServerSerializationStreamReader: the strong name reaches us straight from the
// client (X-GWT-Permutation header) and is concatenated into symbol/source map file names.
private static final Pattern strongNamePattern = Pattern.compile("[a-zA-Z0-9_]+");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ private static StackTraceElement[] trace() {
return new StackTraceElement[] {new StackTraceElement("C", "m", "C.java", 1)};
}

/**
* Builds a frame as the browser reports it for a fragment, whose file name comes from the
* "//# sourceURL=&lt;module&gt;-&lt;fragment&gt;.js" comment written by CrossSiteIframeLinker.
* The column marker makes the frame source map capable, and an unknown method symbol leaves
* the fragment id to be recovered from the file name.
*/
private static StackTraceElement[] traceInFragmentFile(String fileName) {
return new StackTraceElement[] {new StackTraceElement("C", "unknown", fileName + "@1", 1)};
}

private static final String STRONG_NAME = "0F2C4A6E8B1D3F5709ABCDEF12345678";

public void testTraversalStrongNameIsNotUsedToBuildPath() {
RecordingDeobfuscator d = new RecordingDeobfuscator();
d.resymbolize(trace(), "../../../../../../etc/passwd");
Expand All @@ -53,4 +65,25 @@ public void testValidStrongNameStillLoadsSymbolMap() {
d.resymbolize(trace(), "0F2C4A6E8B1D3F5709ABCDEF12345678");
assertEquals("0F2C4A6E8B1D3F5709ABCDEF12345678.symbolMap", d.opened.get(0));
}

public void testSingleDigitFragmentIdIsReadFromFileName() {
RecordingDeobfuscator d = new RecordingDeobfuscator();
d.resymbolize(traceInFragmentFile("app-5.js"), STRONG_NAME);
assertTrue("expected fragment 5 to be requested: " + d.opened,
d.opened.contains(STRONG_NAME + "_sourceMap5.json"));
}

public void testMultiDigitFragmentIdIsReadFromFileName() {
RecordingDeobfuscator d = new RecordingDeobfuscator();
d.resymbolize(traceInFragmentFile("app-12.js"), STRONG_NAME);
assertTrue("expected fragment 12, not its last digit: " + d.opened,
Comment thread
jnehlmeier marked this conversation as resolved.
Outdated
d.opened.contains(STRONG_NAME + "_sourceMap12.json"));
}

public void testMultiDigitFragmentIdIsReadFromModuleNameEndingInDigit() {
RecordingDeobfuscator d = new RecordingDeobfuscator();
d.resymbolize(traceInFragmentFile("app2-104.js"), STRONG_NAME);
assertTrue("expected fragment 104, not its last digit: " + d.opened,
d.opened.contains(STRONG_NAME + "_sourceMap104.json"));
}
}