You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by at...@apache.org on 2026/08/07 16:57:04 UTC
(iceberg-go) branch main updated: fix(rest): reject NUL in namespace identifiers (#1614)
This is an automated email from the ASF dual-hosted git repository.
laskoviymishka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new 9accf2021 fix(rest): reject NUL in namespace identifiers (#1614)
9accf2021 is described below
commit 9accf202108d5893d68c7f06afdc86cca34ecce0
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Fri Aug 7 18:56:58 2026 +0200
fix(rest): reject NUL in namespace identifiers (#1614)
* fix(rest): validate namespace identifier components
Signed-off-by: Minh Vu <vu...@gmail.com>
* fix(rest): preserve existing namespace compatibility
* test(catalog): clarify namespace validation cases
* fix(rest): validate namespace operations
* fix(rest): validate namespace separators
---------
Signed-off-by: Minh Vu <vu...@gmail.com>
---
catalog/catalog.go | 19 +++++++++++++
catalog/identifier_test.go | 34 +++++++++++++++++++++++
catalog/rest/rest.go | 56 ++++++++++++++++++++++++++------------
catalog/rest/rest_internal_test.go | 25 +++++++++++++++++
catalog/rest/rest_test.go | 41 ++++++++++++++++++++++++++++
5 files changed, 158 insertions(+), 17 deletions(-)
diff --git a/catalog/catalog.go b/catalog/catalog.go
index 4ce1c0143..b7348c304 100644
--- a/catalog/catalog.go
+++ b/catalog/catalog.go
@@ -272,6 +272,25 @@ func validateIdentifier(ident table.Identifier, notFoundErr error) error {
return nil
}
+// ValidateNamespaceIdentifier checks that an identifier contains at least one
+// namespace level and no null characters. Other namespace component rules are
+// intentionally left to the catalog implementation so existing namespaces
+// remain readable across clients.
+func ValidateNamespaceIdentifier(ident table.Identifier) error {
+ if len(ident) == 0 {
+ return fmt.Errorf("%w: empty namespace identifier", ErrNoSuchNamespace)
+ }
+
+ for _, part := range ident {
+ if strings.ContainsRune(part, '\x00') {
+ return fmt.Errorf("%w: invalid null character in namespace identifier component %q in %v",
+ ErrNoSuchNamespace, part, strings.Join(ident, "."))
+ }
+ }
+
+ return nil
+}
+
// ValidateTableIdentifier checks that an identifier contains at least one valid namespace level and a table name.
func ValidateTableIdentifier(ident table.Identifier) error {
return validateIdentifier(ident, ErrNoSuchTable)
diff --git a/catalog/identifier_test.go b/catalog/identifier_test.go
index f6a5afa8f..080e3222a 100644
--- a/catalog/identifier_test.go
+++ b/catalog/identifier_test.go
@@ -45,6 +45,40 @@ func TestValidateTableIdentifier(t *testing.T) {
}
}
+func TestValidateNamespaceIdentifier(t *testing.T) {
+ require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{"namespace"}))
+ require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{"parent", "namespace"}))
+ require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{""}))
+ require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{"."}))
+ require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{".."}))
+ require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{"namespace/child"}))
+ require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{"namespace\nchild"}))
+ require.NoError(t, catalog.ValidateNamespaceIdentifier(table.Identifier{"parent", ""}))
+
+ for _, tt := range []struct {
+ name string
+ ident table.Identifier
+ }{
+ {name: "nil", ident: nil},
+ {name: "empty", ident: table.Identifier{}},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ require.ErrorIs(t, catalog.ValidateNamespaceIdentifier(tt.ident), catalog.ErrNoSuchNamespace)
+ })
+ }
+ for _, tt := range []struct {
+ name string
+ ident table.Identifier
+ }{
+ {name: "null character in first component", ident: table.Identifier{"\x00"}},
+ {name: "null character in nested component", ident: table.Identifier{"parent", "child\x00"}},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ require.ErrorIs(t, catalog.ValidateNamespaceIdentifier(tt.ident), catalog.ErrNoSuchNamespace)
+ })
+ }
+}
+
func TestNamespaceFromEmptyIdentifier(t *testing.T) {
require.Nil(t, catalog.NamespaceFromIdent(nil))
require.Nil(t, catalog.NamespaceFromIdent(table.Identifier{}))
diff --git a/catalog/rest/rest.go b/catalog/rest/rest.go
index e47f3f8ae..9cf56170f 100644
--- a/catalog/rest/rest.go
+++ b/catalog/rest/rest.go
@@ -1096,9 +1096,21 @@ func (r *Catalog) Close() error {
var _ catalog.Closer = (*Catalog)(nil)
-func checkValidNamespace(ident table.Identifier) error {
- if len(ident) < 1 {
- return fmt.Errorf("%w: empty namespace identifier", catalog.ErrNoSuchNamespace)
+func (r *Catalog) checkValidNamespace(ident table.Identifier) error {
+ if err := catalog.ValidateNamespaceIdentifier(ident); err != nil {
+ return err
+ }
+
+ separator := r.decodedNamespaceSeparator()
+ if separator == "" {
+ return nil
+ }
+
+ for _, part := range ident {
+ if strings.Contains(part, separator) {
+ return fmt.Errorf("%w: namespace component %q contains the namespace separator %q in %v",
+ catalog.ErrNoSuchNamespace, part, separator, strings.Join(ident, "."))
+ }
}
return nil
@@ -1211,7 +1223,7 @@ func (r *Catalog) ListTables(ctx context.Context, namespace table.Identifier) it
}
func (r *Catalog) listTablesPage(ctx context.Context, namespace table.Identifier, pageToken string, pageSize int) ([]table.Identifier, string, error) {
- if err := checkValidNamespace(namespace); err != nil {
+ if err := r.checkValidNamespace(namespace); err != nil {
return nil, "", err
}
// Unsupported listing yields an empty result rather than an error.
@@ -1270,16 +1282,20 @@ func (r *Catalog) encodeNamespace(namespace table.Identifier) string {
return strings.Join(encoded, r.nsSeparator())
}
-// namespaceToQueryParam joins the raw namespace levels with the decoded
-// separator for use as a query-parameter value, which the HTTP layer then
-// percent-encodes. Mirrors RESTUtil.namespaceToQueryParam in Java.
-func (r *Catalog) namespaceToQueryParam(namespace table.Identifier) string {
+func (r *Catalog) decodedNamespaceSeparator() string {
sep, err := url.PathUnescape(r.nsSeparator())
if err != nil {
- sep = r.nsSeparator()
+ return r.nsSeparator()
}
- return strings.Join(namespace, sep)
+ return sep
+}
+
+// namespaceToQueryParam joins the raw namespace levels with the decoded
+// separator for use as a query-parameter value, which the HTTP layer then
+// percent-encodes. Mirrors RESTUtil.namespaceToQueryParam in Java.
+func (r *Catalog) namespaceToQueryParam(namespace table.Identifier) string {
+ return strings.Join(namespace, r.decodedNamespaceSeparator())
}
func (r *Catalog) splitIdentForPath(ident table.Identifier) (string, string, error) {
@@ -1760,7 +1776,7 @@ func (r *Catalog) CreateNamespace(ctx context.Context, namespace table.Identifie
return err
}
- if err := checkValidNamespace(namespace); err != nil {
+ if err := r.checkValidNamespace(namespace); err != nil {
return err
}
@@ -1782,7 +1798,7 @@ func (r *Catalog) DropNamespace(ctx context.Context, namespace table.Identifier)
return err
}
- if err := checkValidNamespace(namespace); err != nil {
+ if err := r.checkValidNamespace(namespace); err != nil {
return err
}
@@ -1817,6 +1833,12 @@ func (r *Catalog) ListNamespaces(ctx context.Context, parent table.Identifier) (
}
func (r *Catalog) listNamespacesPage(ctx context.Context, parent table.Identifier, pageToken string, pageSize int) ([]table.Identifier, string, error) {
+ if len(parent) != 0 {
+ if err := r.checkValidNamespace(parent); err != nil {
+ return nil, "", err
+ }
+ }
+
// Unsupported listing yields an empty result rather than an error.
if !r.endpoints.allowed(endpointListNamespaces) {
return nil, "", nil
@@ -1861,7 +1883,7 @@ func (r *Catalog) LoadNamespaceProperties(ctx context.Context, namespace table.I
return nil, err
}
- if err := checkValidNamespace(namespace); err != nil {
+ if err := r.checkValidNamespace(namespace); err != nil {
return nil, err
}
@@ -1891,7 +1913,7 @@ func (r *Catalog) UpdateNamespaceProperties(ctx context.Context, namespace table
return catalog.PropertiesUpdateSummary{}, err
}
- if err := checkValidNamespace(namespace); err != nil {
+ if err := r.checkValidNamespace(namespace); err != nil {
return catalog.PropertiesUpdateSummary{}, err
}
@@ -1912,7 +1934,7 @@ func (r *Catalog) UpdateNamespaceProperties(ctx context.Context, namespace table
}
func (r *Catalog) CheckNamespaceExists(ctx context.Context, namespace table.Identifier) (bool, error) {
- if err := checkValidNamespace(namespace); err != nil {
+ if err := r.checkValidNamespace(namespace); err != nil {
return false, err
}
@@ -2005,7 +2027,7 @@ func (r *Catalog) ListViews(ctx context.Context, namespace table.Identifier) ite
}
func (r *Catalog) listViewsPage(ctx context.Context, namespace table.Identifier, pageToken string, pageSize int) ([]table.Identifier, string, error) {
- if err := checkValidNamespace(namespace); err != nil {
+ if err := r.checkValidNamespace(namespace); err != nil {
return nil, "", err
}
// Unsupported listing yields an empty result rather than an error.
@@ -2409,7 +2431,7 @@ func (r *Catalog) ListFunctions(ctx context.Context, namespace table.Identifier)
}
func (r *Catalog) listFunctionsPage(ctx context.Context, namespace table.Identifier, pageToken string, pageSize int) ([]table.Identifier, string, error) {
- if err := checkValidNamespace(namespace); err != nil {
+ if err := r.checkValidNamespace(namespace); err != nil {
return nil, "", err
}
// Unsupported listing yields an empty result rather than an error.
diff --git a/catalog/rest/rest_internal_test.go b/catalog/rest/rest_internal_test.go
index d5198b600..e6e97ec89 100644
--- a/catalog/rest/rest_internal_test.go
+++ b/catalog/rest/rest_internal_test.go
@@ -1882,6 +1882,31 @@ func TestEncodeNamespace(t *testing.T) {
}
}
+func TestCheckValidNamespaceRejectsDecodedSeparator(t *testing.T) {
+ tests := []struct {
+ name string
+ separator string
+ namespace table.Identifier
+ wantErr bool
+ }{
+ {name: "default separator in component", namespace: table.Identifier{"a\x1fb"}, wantErr: true},
+ {name: "configured separator in component", separator: "%2E", namespace: table.Identifier{"a.b"}, wantErr: true},
+ {name: "separator between components", namespace: table.Identifier{"a", "b"}},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cat := &Catalog{namespaceSeparator: tt.separator}
+ err := cat.checkValidNamespace(tt.namespace)
+ if tt.wantErr {
+ require.ErrorIs(t, err, catalog.ErrNoSuchNamespace)
+ } else {
+ require.NoError(t, err)
+ }
+ })
+ }
+}
+
func TestNamespaceSeparatorFromConfig(t *testing.T) {
mux := http.NewServeMux()
srv := httptest.NewServer(mux)
diff --git a/catalog/rest/rest_test.go b/catalog/rest/rest_test.go
index b6788bd61..2649c404c 100644
--- a/catalog/rest/rest_test.go
+++ b/catalog/rest/rest_test.go
@@ -807,6 +807,47 @@ func (r *RestCatalogSuite) TestListNamespaceWithParent200() {
r.Equal([]table.Identifier{{"accounting", "tax"}}, results)
}
+func (r *RestCatalogSuite) TestNamespaceOperationsRejectInvalidComponents() {
+ requestCount := 0
+ r.mux.HandleFunc("/v1/namespaces", func(w http.ResponseWriter, req *http.Request) {
+ requestCount++
+ })
+ r.mux.HandleFunc("/v1/namespaces/", func(w http.ResponseWriter, req *http.Request) {
+ requestCount++
+ })
+
+ cat, err := rest.NewCatalog(context.Background(), "rest", r.srv.URL, rest.WithOAuthToken(TestToken))
+ r.Require().NoError(err)
+
+ for _, namespace := range []table.Identifier{
+ {"bad\x00name"},
+ {"a\x1fb"},
+ } {
+ r.ErrorIs(cat.CreateNamespace(context.Background(), namespace, nil), catalog.ErrNoSuchNamespace)
+ r.ErrorIs(cat.DropNamespace(context.Background(), namespace), catalog.ErrNoSuchNamespace)
+ _, err = cat.LoadNamespaceProperties(context.Background(), namespace)
+ r.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ _, err = cat.UpdateNamespaceProperties(context.Background(), namespace, nil, nil)
+ r.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ _, err = cat.CheckNamespaceExists(context.Background(), namespace)
+ r.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ _, err = cat.ListNamespaces(context.Background(), namespace)
+ r.ErrorIs(err, catalog.ErrNoSuchNamespace)
+
+ for _, err := range cat.ListTables(context.Background(), namespace) {
+ r.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ }
+ for _, err := range cat.ListViews(context.Background(), namespace) {
+ r.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ }
+ for _, err := range cat.ListFunctions(context.Background(), namespace) {
+ r.ErrorIs(err, catalog.ErrNoSuchNamespace)
+ }
+ }
+
+ r.Zero(requestCount)
+}
+
func (r *RestCatalogSuite) TestListNamespaces400() {
r.mux.HandleFunc("/v1/namespaces", func(w http.ResponseWriter, req *http.Request) {
r.Require().Equal(http.MethodGet, req.Method)