Skip to content

Commit ccb20dc

Browse files
authored
Fix #991: change default setting for StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION to false (#1038)
1 parent 073183c commit ccb20dc

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ a pure JSON library.
1616

1717
2.16.0 (not yet released)
1818

19+
#991: Change `StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` default to `false`
20+
in Jackson 2.16
21+
(suggested by @quinlam)
1922
#1007: Improve error message for `StreamReadConstraints` violations
2023
#1015: `JsonFactory` implementations should respect `CANONICALIZE_FIELD_NAMES`
2124
(contributed by Carter K)

src/main/java/com/fasterxml/jackson/core/JsonParser.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,15 @@ public enum Feature {
329329
* printed, and not the whole contents. Further, many source reference types can not
330330
* necessarily access contents (like streams), so only type is indicated, not contents.
331331
*<p>
332-
* Feature is enabled by default, meaning that "source reference" information is passed
333-
* and some or all of the source content may be included in {@link JsonLocation} information
334-
* constructed either when requested explicitly, or when needed for an exception.
332+
* Since 2.16 feature is <b>disabled</b> by default (before 2.16 it was enabled),
333+
* meaning that "source reference" information is NOT passed; this for security
334+
* reasons (so by default no information is leaked; see
335+
* <a href="https://github.com/FasterXML/jackson-core/issues/991">core#991</a>
336+
* for more)
335337
*
336-
* @since 2.9
338+
* @since 2.9 (but different default since 2.16)
337339
*/
338-
INCLUDE_SOURCE_IN_LOCATION(true),
340+
INCLUDE_SOURCE_IN_LOCATION(false),
339341

340342
/**
341343
* Feature that determines whether we use the built-in {@link Double#parseDouble(String)} code to parse

src/test/java/com/fasterxml/jackson/core/TestExceptions.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class TestExceptions extends BaseTest
99
{
10-
private final JsonFactory JSON_F = new JsonFactory();
10+
private final JsonFactory JSON_F = newStreamFactory();
1111

1212
// For [core#10]
1313
public void testOriginalMesssage()
@@ -123,26 +123,30 @@ private void _testEofExceptions(int mode) throws Exception
123123

124124
public void testContentSnippetWithOffset() throws Exception
125125
{
126+
final JsonFactory jsonF = this.streamFactoryBuilder()
127+
.enable(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION)
128+
.build();
129+
126130
JsonParser p;
127131
final String json = a2q("{'k1':'v1'}\n[broken]\n");
128132
final byte[] jsonB = utf8Bytes(json);
129133
final int lfIndex = json.indexOf("\n");
130134
final int start = lfIndex+1;
131135
final int len = json.length() - start;
132136

133-
p = JSON_F.createParser(jsonB, start, len);
137+
p = jsonF.createParser(jsonB, start, len);
134138
// for byte-based, will be after character that follows token:
135139
// (and alas cannot be easily fixed)
136140
_testContentSnippetWithOffset(p, 9, "(byte[])\"[broken]\n\"");
137141
p.close();
138142

139143
final char[] jsonC = json.toCharArray();
140-
p = JSON_F.createParser(jsonC, start, len);
144+
p = jsonF.createParser(jsonC, start, len);
141145
// for char-based we get true offset at end of token
142146
_testContentSnippetWithOffset(p, 8, "(char[])\"[broken]\n\"");
143147
p.close();
144148

145-
p = JSON_F.createParser(json.substring(start));
149+
p = jsonF.createParser(json.substring(start));
146150
// for char-based we get true offset at end of token
147151
_testContentSnippetWithOffset(p, 8, "(String)\"[broken]\n\"");
148152
p.close();
@@ -161,7 +165,6 @@ private void _testContentSnippetWithOffset(final JsonParser p,
161165
assertEquals(1, loc.getLineNr());
162166
assertEquals(expColumn, loc.getColumnNr());
163167
final String srcDesc = loc.sourceDescription();
164-
165168
assertEquals(expContent, srcDesc);
166169
}
167170
}

0 commit comments

Comments
 (0)