Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit adb8ced

Browse files
committed
Refresh sys.indexes (UUF 482008)
1 parent a4eb6d1 commit adb8ced

3 files changed

Lines changed: 164 additions & 152 deletions

File tree

docs/includes/sscatviewperm-md.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
author: rwestMSFT
33
ms.author: randolphwest
4-
ms.date: 03/19/2024
4+
ms.date: 08/21/2025
55
ms.service: sql
66
ms.topic: include
77
---
8-
The visibility of the metadata in catalog views is limited to securables that a user either owns, or on which the user was granted some permission.
8+
The visibility of the metadata in catalog views is limited to securables that a user either owns, or on which the user was granted some permission.

docs/relational-databases/security/metadata-visibility-configuration.md

Lines changed: 73 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ title: "Metadata Visibility Configuration"
33
description: Learn how to configure metadata visibility for securables that a user owns or has been granted permission to in SQL Server.
44
author: VanMSFT
55
ms.author: vanto
6-
ms.date: 07/31/2025
6+
ms.reviewer: randolphwest
7+
ms.date: 08/21/2025
78
ms.service: sql
89
ms.subservice: security
910
ms.topic: conceptual
@@ -24,7 +25,7 @@ monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >
2425

2526
The visibility of metadata is limited to securables that a user either owns or on which the user has been granted some permission.
2627

27-
For example, the following query returns a row if the user grants a permission such as SELECT or INSERT on the table `myTable`.
28+
For example, the following query returns a row if the user grants a permission such as `SELECT` or `INSERT` on the table `myTable`.
2829

2930
```sql
3031
SELECT name, object_id
@@ -60,7 +61,7 @@ Limited metadata accessibility means the following:
6061
- Queries on system views might only return a subset of rows, or sometimes an empty result set.
6162
- Metadata-emitting, built-in functions such as OBJECTPROPERTYEX might return `NULL`.
6263
- The [!INCLUDE [ssDE](../../includes/ssde-md.md)] `sp_help` stored procedures might return only a subset of rows, or `NULL`.
63-
- As a result, applications that assume **public** metadata access will break.
64+
- As a result, applications that assume **public** metadata access breaks.
6465

6566
SQL modules, such as stored procedures and triggers, run under the security context of the caller and, therefore, have limited metadata accessibility. For example, in the following code, when the stored procedure tries to access metadata for the table `myTable` on which the caller has no rights, an empty result set is returned. In earlier releases of [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)], a row is returned.
6667

@@ -74,43 +75,43 @@ END;
7475
GO
7576
```
7677

77-
To allow callers to view metadata, you can grant the callers VIEW DEFINITION permission or starting with SQL Server 2022 either VIEW SECURITY DEFINITION or VIEW PERFORMANCE DEFINITION at an appropriate scope: object level, database level, or server level. Therefore, in the previous example, if the caller has VIEW DEFINITION permission on `myTable`, the stored procedure returns a row. For more information, see [GRANT (Transact-SQL)](../../t-sql/statements/grant-transact-sql.md) and [GRANT Database Permissions (Transact-SQL)](../../t-sql/statements/grant-database-permissions-transact-sql.md).
78+
To allow callers to view metadata, you can grant the callers `VIEW DEFINITION` permission, or in [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions, either `VIEW SECURITY DEFINITION` or `VIEW PERFORMANCE DEFINITION` at an appropriate scope: object level, database level, or server level. Therefore, in the previous example, if the caller has `VIEW DEFINITION` permission on `myTable`, the stored procedure returns a row. For more information, see [GRANT](../../t-sql/statements/grant-transact-sql.md) and [GRANT Database Permissions](../../t-sql/statements/grant-database-permissions-transact-sql.md).
7879

7980
You can also modify the stored procedure so that it executes under the credentials of the owner. When the procedure owner and the table owner are the same owner, ownership chaining applies, and the security context of the procedure owner enables access to the metadata for `myTable`. Under this scenario, the following code returns a row of metadata to the caller.
8081

8182
> [!NOTE]
82-
> The following example uses the [sys.objects](../../relational-databases/system-catalog-views/sys-objects-transact-sql.md) catalog view instead of the [sys.sysobjects](../../relational-databases/system-compatibility-views/sys-sysobjects-transact-sql.md) compatibility view.
83+
> The following example uses the [sys.objects](../system-catalog-views/sys-objects-transact-sql.md) catalog view instead of the [sys.sysobjects](../system-compatibility-views/sys-sysobjects-transact-sql.md) compatibility view.
8384
8485
```sql
8586
CREATE PROCEDURE does_not_assume_caller_can_access_metadata
8687
WITH EXECUTE AS OWNER
8788
AS
8889
BEGIN
89-
SELECT name, object_id
90-
FROM sys.objects
91-
WHERE name = N'myTable'
92-
END;
90+
SELECT name, object_id
91+
FROM sys.objects
92+
WHERE name = N'myTable';
93+
END
9394
GO
9495
```
9596

9697
> [!NOTE]
97-
> You can use EXECUTE AS to temporarily switch to the security context of the caller. For more information, see [EXECUTE AS (Transact-SQL)](../../t-sql/statements/execute-as-transact-sql.md).
98+
> You can use `EXECUTE AS` to temporarily switch to the security context of the caller. For more information, see [EXECUTE AS](../../t-sql/statements/execute-as-transact-sql.md).
9899
99100
## Benefits and limits of metadata visibility configuration
100101

101102
Metadata visibility configuration can play an important role in your overall security plan. However, there are cases in which a skilled and determined user can force the disclosure of some metadata. We recommend that you deploy metadata permissions as one of many defenses-in-depth.
102103

103-
It's theoretically possible to force the emission of metadata in error messages by manipulating the order of predicate evaluation in queries. The possibility of such *trial-and-error attacks* isn't specific to [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)]. It's implied by the associative and commutative transformations permitted in relational algebra. You can mitigate this risk by limiting the information returned in error messages. To further restrict the visibility of metadata in this way, you can start the server with trace flag 3625. This trace flag limits the amount of information shown in error messages. In turn, this helps to prevent forced disclosures. The tradeoff is that error messages will be terse and might be difficult to use for debugging purposes. For more information, see [Database Engine Service Startup Options](../../database-engine/configure-windows/database-engine-service-startup-options.md) and [Trace Flags (Transact-SQL)](../../t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql.md).
104+
It's theoretically possible to force the emission of metadata in error messages by manipulating the order of predicate evaluation in queries. The possibility of such *trial-and-error attacks* isn't specific to [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)]. It's implied by the associative and commutative transformations permitted in relational algebra. You can mitigate this risk by limiting the information returned in error messages. To further restrict the visibility of metadata in this way, you can start the server with trace flag 3625. This trace flag limits the amount of information shown in error messages. In turn, this helps to prevent forced disclosures. The tradeoff is that error messages are terse and might be difficult to use for debugging purposes. For more information, see [Database Engine Service startup options](../../database-engine/configure-windows/database-engine-service-startup-options.md) and [Trace Flags](../../t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql.md).
104105

105106
The following metadata isn't subject to forced disclosure:
106107

107-
- The value stored in the `provider_string` column of `sys.servers`. A user that doesn't have **ALTER ANY LINKED SERVER** permission will see a `NULL` value in this column.
108+
- The value stored in the `provider_string` column of `sys.servers`. A user that doesn't have `ALTER ANY LINKED SERVER` permission sees a `NULL` value in this column.
108109

109-
- Source definition of a user-defined object such as a stored procedure or trigger. The source code is visible only when one of the following is true:
110+
- Source definition of a user-defined object such as a stored procedure or trigger. The source code is visible only when one of the following conditions is true:
110111

111-
- The user has **VIEW DEFINITION** permission on the object.
112+
- The user has `VIEW DEFINITION` permission on the object.
112113

113-
- The user hasn't been denied **VIEW DEFINITION** permission on the object and has **CONTROL**, **ALTER**, or **TAKE OWNERSHIP** permission on the object. All other users will see `NULL`.
114+
- The user hasn't been denied `VIEW DEFINITION` permission on the object and has `CONTROL`, `ALTER`, or `TAKE OWNERSHIP` permission on the object. All other users see `NULL`.
114115

115116
- The definition columns found in the following catalog views:
116117

@@ -135,12 +136,11 @@ The following metadata isn't subject to forced disclosure:
135136
- `INFORMATION_SCHEMA.ROUTINE_COLUMNS.COLUMN_DEFAULT`
136137
- `INFORMATION_SCHEMA.VIEWS.VIEW_DEFINITION`
137138

138-
- OBJECT_DEFINITION() function
139+
- `OBJECT_DEFINITION()` function
139140

140-
- The value stored in the password_hash column of `sys.sql_logins`. A user that doesn't have **CONTROL SERVER** or starting with SQL Server 2022 the **VIEW ANY CRYPTOGRAPHICALLY SECURED DEFINITION** permission will see a `NULL` value in this column.
141+
- The value stored in the `password_hash` column of `sys.sql_logins`. A user that doesn't have `CONTROL SERVER`, or in [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions, the `VIEW ANY CRYPTOGRAPHICALLY SECURED DEFINITION` permission sees a `NULL` value in this column.
141142

142-
> [!NOTE]
143-
> The SQL definitions of built-in system procedures and functions are publicly visible through the `sys.system_sql_modules` catalog view, the `sp_helptext` stored procedure, and the OBJECT_DEFINITION() function.
143+
The SQL definitions of built-in system procedures and functions are publicly visible through the `sys.system_sql_modules` catalog view, the `sp_helptext` stored procedure, and the `OBJECT_DEFINITION()` function.
144144

145145
> [!NOTE]
146146
> The system stored procedure `sp_helptext` isn't supported in Azure Synapse Analytics. Instead, use the `sys.sql_modules` object catalog view.
@@ -150,11 +150,8 @@ The following metadata isn't subject to forced disclosure:
150150
The following are some general principles to consider regarding metadata visibility:
151151

152152
- Fixed roles implicit permissions
153-
154153
- Scope of permissions
155-
156-
- Precedence of DENY
157-
154+
- Precedence of `DENY`
158155
- Visibility of subcomponent metadata
159156

160157
### Fixed roles and implicit permissions
@@ -163,106 +160,101 @@ Metadata that can be accessed by fixed roles depends upon their corresponding im
163160

164161
### Scope of permissions
165162

166-
Permissions at one scope imply the ability to see metadata at that scope and at all enclosed scopes. For example, **SELECT** permission on a schema implies that the grantee has **SELECT** permission on all securables that are contained by that schema. The granting of **SELECT** permission on a schema therefore enables a user to see the metadata of the schema and also all tables, views, functions, procedures, queues, synonyms, types, and XML schema collections within it. For more information about scopes, see [Permissions Hierarchy (Database Engine)](../../relational-databases/security/permissions-hierarchy-database-engine.md).
163+
Permissions at one scope imply the ability to see metadata at that scope and at all enclosed scopes. For example, `SELECT` permission on a schema implies that the grantee has `SELECT` permission on all securables that are contained by that schema. The granting of `SELECT` permission on a schema therefore enables a user to see the metadata of the schema and also all tables, views, functions, procedures, queues, synonyms, types, and XML schema collections within it. For more information about scopes, see [Permissions Hierarchy (Database Engine)](permissions-hierarchy-database-engine.md).
167164

168165
> [!NOTE]
169-
> The **UNMASK** permission doesn't influence metadata visibility: granting **UNMASK** alone won't disclose any Metadata. **UNMASK** will always need to be accompanied by a **SELECT** permission to have any effect. Example: granting **UNMASK** on database scope and granting **SELECT** on an individual Table will have the result that the user can only see the metadata of the individual table from which they can select, not any others.
166+
> The `UNMASK` permission doesn't influence metadata visibility: granting `UNMASK` alone doesn't disclose any Metadata. `UNMASK` always needs to be accompanied by a `SELECT` permission to have any effect. Example: granting `UNMASK` on database scope and granting `SELECT` on an individual table has the result that the user can only see the metadata of the individual table from which they can select, not any others.
170167
171168
### Precedence of DENY
172169

173-
**DENY** typically takes precedence over other permissions. For example, if a database user is granted **EXECUTE** permission on a schema but has been denied **EXECUTE** permission on a stored procedure in that schema, the user can't view the metadata for that stored procedure.
170+
`DENY` typically takes precedence over other permissions. For example, if a database user is granted `EXECUTE` permission on a schema but has been denied `EXECUTE` permission on a stored procedure in that schema, the user can't view the metadata for that stored procedure.
174171

175-
Additionally, if a user is denied **EXECUTE** permission on a schema but has been granted **EXECUTE** permission on a stored procedure in that schema, the user can't view the metadata for that stored procedure.
172+
Additionally, if a user is denied `EXECUTE` permission on a schema but has been granted `EXECUTE` permission on a stored procedure in that schema, the user can't view the metadata for that stored procedure.
176173

177-
For another example, if a user has been granted and denied **EXECUTE** permission on a stored procedure, which is possible through your various role memberships, **DENY** takes precedence and the user can't view the metadata of the stored procedure.
174+
For another example, if a user has been granted and denied `EXECUTE` permission on a stored procedure, which is possible through your various role memberships, `DENY` takes precedence and the user can't view the metadata of the stored procedure.
178175

179176
### Visibility of subcomponent metadata
180177

181-
The visibility of subcomponents, such as indexes, check constraints, and triggers are determined by permissions on the parent. These subcomponents don't have grantable permissions. For example, if a user has been granted some permission on a table, the user can view the metadata for the tables, columns, indexes, check constraints, triggers, and other such subcomponents. Another example is granting **SELECT** on only an individual column of a given table: this will allow the grantee to view the metadata of the whole table, including all columns. One way to think of it, is that the **VIEW DEFINITION** permission only works on entity-level (the table in this case) and isn't available for Subentity lists (such as column or security expressions).
178+
The visibility of subcomponents, such as indexes, check constraints, and triggers are determined by permissions on the parent. These subcomponents don't have grantable permissions. For example, if a user has been granted some permission on a table, the user can view the metadata for the tables, columns, indexes, check constraints, triggers, and other such subcomponents. Another example is granting `SELECT` on only an individual column of a given table: this allows the grantee to view the metadata of the whole table, including all columns. One way to think of it, is that the `VIEW DEFINITION` permission only works on entity-level (the table in this case) and isn't available for Subentity lists (such as column or security expressions).
182179

183180
The following code demonstrates this behavior:
184181

185182
```sql
186183
CREATE TABLE t1
187184
(
188-
c1 int,
189-
c2 varchar
190-
);
185+
c1 INT,
186+
c2 VARCHAR
187+
);
191188
GO
189+
192190
CREATE USER testUser WITHOUT LOGIN;
193191
GO
194192

195-
EXECUTE AS USER='testUser';
196-
SELECT OBJECT_SCHEMA_NAME(object_id), OBJECT_NAME(object_id), name FROM sys.columns;
197-
SELECT * FROM sys.tables
193+
EXECUTE AS USER = 'testUser';
194+
195+
SELECT OBJECT_SCHEMA_NAME(object_id),
196+
OBJECT_NAME(object_id),
197+
name
198+
FROM sys.columns;
199+
200+
SELECT * FROM sys.tables;
198201
-- this returns no data, as the user has no permissions
202+
199203
REVERT;
200204
GO
201205

202206
-- granting SELECT on only 1 column of the table:
203-
GRANT SELECT ON t1(c1) TO testUser;
207+
GRANT SELECT ON t1 (c1) TO testUser;
204208
GO
205-
EXECUTE AS USER='testUser';
206-
SELECT OBJECT_SCHEMA_NAME(object_id), OBJECT_NAME(object_id), name FROM sys.columns;
207-
SELECT * FROM sys.tables
209+
210+
EXECUTE AS USER = 'testUser';
211+
212+
SELECT OBJECT_SCHEMA_NAME(object_id),
213+
OBJECT_NAME(object_id),
214+
name
215+
FROM sys.columns;
216+
217+
SELECT * FROM sys.tables;
208218
-- this returns metadata for all columns of the table and the table itself
219+
;
220+
209221
REVERT;
210222
GO
211223

212-
DROP TABLE t1
213-
DROP USER testUser
224+
DROP TABLE t1;
225+
DROP USER testUser;
214226
```
215227

216228
#### Metadata that is accessible to all database users
217229

218-
Some metadata must be accessible to all users in a specific database. For example, filegroups don't have conferrable permissions; therefore, a user can't be granted permission to view the metadata of a filegroup. However, any user that can create a table must be able to access filegroup metadata to use the ON *filegroup* or TEXTIMAGE_ON *filegroup* clauses of the CREATE TABLE statement.
230+
Some metadata must be accessible to all users in a specific database. For example, filegroups don't have conferrable permissions; therefore, a user can't be granted permission to view the metadata of a filegroup. However, any user that can create a table must be able to access filegroup metadata to use the `ON <filegroup>` or `TEXTIMAGE_ON <filegroup>` clauses of the `CREATE TABLE` statement.
219231

220-
The metadata that is returned by the DB_ID() and DB_NAME() functions is visible to all users.
232+
The metadata that is returned by the `DB_ID()` and `DB_NAME()` functions is visible to all users.
221233

222234
This is a list of the catalog views that are visible to the **public** role.
223235

224-
:::row:::
225-
:::column:::
226-
`sys.partition_functions`
227-
228-
`sys.partition_schemes`
229-
230-
`sys.filegroups`
231-
232-
`sys.database_files`
233-
234-
`sys.partitions`
235-
236-
`sys.schemas`
237-
238-
`sys.sql_dependencies`
239-
240-
`sys.parameter_type_usages`
241-
:::column-end:::
242-
:::column:::
243-
`sys.partition_range_values`
244-
245-
`sys.data_spaces`
246-
247-
`sys.destination_data_spaces`
248-
249-
`sys.allocation_units`
250-
251-
`sys.messages`
252-
253-
`sys.configurations`
254-
255-
`sys.type_assembly_usages`
256-
257-
`sys.column_type_usages`
258-
:::column-end:::
259-
:::row-end:::
236+
- `sys.allocation_units`
237+
- `sys.column_type_usages`
238+
- `sys.configurations`
239+
- `sys.data_spaces`
240+
- `sys.database_files`
241+
- `sys.destination_data_spaces`
242+
- `sys.filegroups`
243+
- `sys.messages`
244+
- `sys.parameter_type_usages`
245+
- `sys.partition_functions`
246+
- `sys.partition_range_values`
247+
- `sys.partition_schemes`
248+
- `sys.partitions`
249+
- `sys.schemas`
250+
- `sys.sql_dependencies`
251+
- `sys.type_assembly_usages`
260252

261253
## Related content
262254

263255
- [GRANT (Transact-SQL)](../../t-sql/statements/grant-transact-sql.md)
264256
- [DENY (Transact-SQL)](../../t-sql/statements/deny-transact-sql.md)
265257
- [REVOKE (Transact-SQL)](../../t-sql/statements/revoke-transact-sql.md)
266258
- [EXECUTE AS Clause (Transact-SQL)](../../t-sql/statements/execute-as-clause-transact-sql.md)
267-
- [Catalog Views (Transact-SQL)](../../relational-databases/system-catalog-views/catalog-views-transact-sql.md)
268-
- [Compatibility Views (Transact-SQL)](~/relational-databases/system-compatibility-views/system-compatibility-views-transact-sql.md)
259+
- [System catalog views (Transact-SQL)](../system-catalog-views/catalog-views-transact-sql.md)
260+
- [System Compatibility Views (Transact-SQL)](../system-compatibility-views/system-compatibility-views-transact-sql.md)

0 commit comments

Comments
 (0)