Skip to content

Commit 8584f0f

Browse files
authored
Merge pull request #3711 from atlanhq/plt-2751-idx-limit
PLT-2751 : Abuse protection in Indexsearch endpoint: Put limit in indexsearch size upto 100000
2 parents dd3dc3d + 02a7b1b commit 8584f0f

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

intg/src/main/java/org/apache/atlas/AtlasConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public enum AtlasConfiguration {
113113
HERACLES_API_SERVER_URL("atlas.heracles.api.service.url", "http://heracles-service.heracles.svc.cluster.local"),
114114

115115
INDEXSEARCH_ASYNC_SEARCH_KEEP_ALIVE_TIME_IN_SECONDS("atlas.indexsearch.async.search.keep.alive.time.in.seconds", 300),
116+
ATLAS_INDEXSEARCH_QUERY_SIZE_MAX_LIMIT("atlas.indexsearch.query.size.max.limit", 100000),
117+
ATLAS_INDEXSEARCH_LIMIT_UTM_TAGS("atlas.indexsearch.limit.ignore.utm.tags", "project_sdk_python"),
116118

117119
ATLAS_MAINTENANCE_MODE("atlas.maintenance.mode", false),
118120

intg/src/main/java/org/apache/atlas/AtlasErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public enum AtlasErrorCode {
121121
INVALID_DSL_DUPLICATE_ALIAS(400, "ATLAS-400-00-066", "DSL Semantic Error - Duplicate alias found: '{0}' for type '{1}' already present."),
122122
INVALID_DSL_INVALID_DATE(400, "ATLAS-400-00-067", "DSL Semantic Error - Date format: {0}."),
123123
INVALID_DSL_HAS_PROPERTY(400, "ATLAS-400-00-068", "DSL Semantic Error - Property needs to be a primitive type: {0}"),
124+
INVALID_DSL_QUERY_SIZE(400, "ATLAS-400-00-103", "DSL Error - Please provide query size less than {0}"),
124125
RELATIONSHIP_UPDATE_END_CHANGE_NOT_ALLOWED(404, "ATLAS-400-00-069", "change of relationship end is not permitted. relationship-type={0}, relationship-guid={1}, end-guid={2}, updated-end-guid={3}"),
125126
RELATIONSHIP_UPDATE_TYPE_CHANGE_NOT_ALLOWED(404, "ATLAS-400-00-06A", "change of relationship type is not permitted. relationship-guid={0}, current-type={1}, new-type={2}"),
126127
CLASSIFICATION_UPDATE_FROM_PROPAGATED_ENTITY(400, "ATLAS-400-00-06B", "Update to classification {0} is not allowed from propagated entity"),

intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public void setDsl(Map dsl) {
4444
queryString = AtlasType.toJson(dsl);
4545
}
4646

47+
public long getQuerySize() {
48+
return dsl.get("size") != null ? ((Number)dsl.get("size")).longValue() : 10;
49+
}
50+
4751
public boolean isAllowDeletedRelations() {
4852
return allowDeletedRelations;
4953
}

webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import java.util.List;
6868
import java.util.Set;
6969
import java.util.Arrays;
70+
7071
import static org.apache.atlas.repository.Constants.QUALIFIED_NAME;
7172
import static org.apache.atlas.repository.Constants.REQUEST_HEADER_HOST;
7273
import static org.apache.atlas.repository.Constants.REQUEST_HEADER_USER_AGENT;
@@ -400,6 +401,17 @@ public AtlasSearchResult indexSearch(@Context HttpServletRequest servletRequest,
400401
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DiscoveryREST.indexSearch(" + parameters + ")");
401402
}
402403

404+
if (parameters.getQuerySize() > AtlasConfiguration.ATLAS_INDEXSEARCH_QUERY_SIZE_MAX_LIMIT.getLong()) {
405+
if(CollectionUtils.isEmpty(parameters.getUtmTags())) {
406+
throw new AtlasBaseException(AtlasErrorCode.INVALID_DSL_QUERY_SIZE, String.valueOf(AtlasConfiguration.ATLAS_INDEXSEARCH_QUERY_SIZE_MAX_LIMIT.getLong()));
407+
}
408+
for (String utmTag : parameters.getUtmTags()) {
409+
if (Arrays.stream(AtlasConfiguration.ATLAS_INDEXSEARCH_LIMIT_UTM_TAGS.getStringArray()).anyMatch(utmTag::equalsIgnoreCase)) {
410+
throw new AtlasBaseException(AtlasErrorCode.INVALID_DSL_QUERY_SIZE, String.valueOf(AtlasConfiguration.ATLAS_INDEXSEARCH_QUERY_SIZE_MAX_LIMIT.getLong()));
411+
}
412+
}
413+
}
414+
403415
if (StringUtils.isEmpty(parameters.getQuery())) {
404416
AtlasBaseException abe = new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Invalid search query");
405417
if (enableSearchLogging && parameters.isSaveSearchLog()) {

0 commit comments

Comments
 (0)