Skip to content

Commit 0d8b753

Browse files
authored
IndexClosedException to return 400 rather than 403 (#25752)
403 can be confused with security. If an API doesn't support working against closed indices and closed indices are referred to in a request, that is a bad request, hence 400 is more appropriate.
1 parent 194f267 commit 0d8b753

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

core/src/main/java/org/elasticsearch/indices/IndexClosedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public IndexClosedException(StreamInput in) throws IOException{
4242

4343
@Override
4444
public RestStatus status() {
45-
return RestStatus.FORBIDDEN;
45+
return RestStatus.BAD_REQUEST;
4646
}
4747
}

docs/reference/migration/migrate_6_0/rest.asciidoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ $ curl -v -XPOST 'localhost:9200/my_index/_settings'
107107
* Connection #0 to host localhost left intact
108108
--------------------------------------------
109109

110-
==== Dissallow using `_cache` and `_cache_key`
110+
==== Disallow using `_cache` and `_cache_key`
111111

112112
The `_cache` and `_cache_key` options in queries have been deprecated since version 2.0.0 and
113113
have been ignored since then, issuing a deprecation warning. These options have now been completely
114114
removed, so using them now will throw an error.
115+
116+
==== IndexClosedException to return 400 status code
117+
118+
An `IndexClosedException` is returned whenever an api that doesn't support
119+
closed indices (e.g. search) is called passing closed indices as parameters
120+
and `ignore_unavailable` is set to `false`. The response status code returned
121+
in such case changed from `403` to `400`

rest-api-spec/src/main/resources/rest-api-spec/test/cat.segments/10_basic.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
---
8787
"Test cat segments on closed index behaviour":
8888

89+
- skip:
90+
version: " - 5.99.99"
91+
reason: status code on closed indices changed in 6.0.0 from 403 to 400
92+
8993
- do:
9094
indices.create:
9195
index: index1
@@ -99,7 +103,7 @@
99103
index: index1
100104

101105
- do:
102-
catch: forbidden
106+
catch: request
103107
cat.segments:
104108
index: index1
105109

rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/10_basic.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
---
22
"Basic test for index open/close":
3+
- skip:
4+
version: " - 5.99.99"
5+
reason: status code on closed indices changed in 6.0.0 from 403 to 400
6+
37
- do:
48
indices.create:
59
index: test_index
@@ -16,7 +20,7 @@
1620
index: test_index
1721

1822
- do:
19-
catch: forbidden
23+
catch: request
2024
search:
2125
index: test_index
2226

rest-api-spec/src/main/resources/rest-api-spec/test/indices.open/20_multiple_indices.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ setup:
2323

2424
---
2525
"All indices":
26+
- skip:
27+
version: " - 5.99.99"
28+
reason: status code on closed indices changed in 6.0.0 from 403 to 400
29+
2630
- do:
2731
indices.close:
2832
index: _all
2933

3034
- do:
31-
catch: forbidden
35+
catch: request
3236
search:
3337
index: test_index2
3438

@@ -46,12 +50,16 @@ setup:
4650

4751
---
4852
"Trailing wildcard":
53+
- skip:
54+
version: " - 5.99.99"
55+
reason: status code on closed indices changed in 6.0.0 from 403 to 400
56+
4957
- do:
5058
indices.close:
5159
index: test_*
5260

5361
- do:
54-
catch: forbidden
62+
catch: request
5563
search:
5664
index: test_index2
5765

@@ -69,12 +77,16 @@ setup:
6977

7078
---
7179
"Only wildcard":
80+
- skip:
81+
version: " - 5.99.99"
82+
reason: status code on closed indices changed in 6.0.0 from 403 to 400
83+
7284
- do:
7385
indices.close:
7486
index: '*'
7587

7688
- do:
77-
catch: forbidden
89+
catch: request
7890
search:
7991
index: test_index3
8092

rest-api-spec/src/main/resources/rest-api-spec/test/indices.segments/10_basic.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343

4444
---
4545
"closed segments test":
46+
- skip:
47+
version: " - 5.99.99"
48+
reason: status code on closed indices changed in 6.0.0 from 403 to 400
4649

4750
- do:
4851
indices.create:
@@ -63,7 +66,7 @@
6366
index: index1
6467

6568
- do:
66-
catch: forbidden
69+
catch: request
6770
indices.segments:
6871
index: index1
6972

0 commit comments

Comments
 (0)