Bug #121918 ROUTINE_LIBRARIES exposes referenced library without library privilege
Description:
INFORMATION_SCHEMA.ROUTINE_LIBRARIES exposes a referenced library to an account that has EXECUTE privilege on the importing function but no privilege on the library itself.
A SQL SECURITY DEFINER function verifies that it is executing as the low-privilege definer and then checks for the relationship row. The query returns 1:
unauthorized_library_metadata_visible
1
The account should not see the relationship row because its library endpoint is not visible to that account. Revoking EXECUTE on the importing function makes the same guarded query fail with error 1772, confirming that visibility is currently authorized from the importing-function side only.
How to repeat:
Run as root:
DROP DATABASE IF EXISTS db1;
DROP USER IF EXISTS 'u1'@'%';
CREATE DATABASE db1;
CREATE LIBRARY db1.lib1
LANGUAGE JAVASCRIPT
AS 'export function f() { return 7; }';
CREATE FUNCTION db1.target()
RETURNS INT
DETERMINISTIC
NO SQL
LANGUAGE JAVASCRIPT
USING (db1.lib1 AS lib)
AS 'return lib.f();';
CREATE USER 'u1'@'%';
CREATE DEFINER='u1'@'%'
FUNCTION db1.oracle1()
RETURNS INT
DETERMINISTIC
READS SQL DATA
SQL SECURITY DEFINER
RETURN IF(
CURRENT_USER() = 'u1@%',
IF(
EXISTS(
SELECT 1
FROM information_schema.ROUTINE_LIBRARIES
WHERE ROUTINE_SCHEMA = 'db1'
AND ROUTINE_NAME = 'target'
AND LIBRARY_SCHEMA = 'db1'
AND LIBRARY_NAME = 'lib1'
),
1,
GTID_SUBSET('not-a-gtid', '')
),
GTID_SUBSET('not-a-gtid', '')
);
GRANT EXECUTE ON FUNCTION db1.target TO 'u1'@'%';
GRANT EXECUTE ON FUNCTION db1.oracle1 TO 'u1'@'%';
SELECT db1.oracle1() AS unauthorized_library_metadata_visible;
-- Observed: returns 1.
-- Expected: error 1772, because the definer has no privilege on db1.lib1
-- and therefore should not see this relationship row.
Suggested fix:
Require authorization for both the importing routine and the referenced library before exposing a row through INFORMATION_SCHEMA.ROUTINE_LIBRARIES.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: INFORMATION_SCHEMA.ROUTINE_LIBRARIES exposes a referenced library to an account that has EXECUTE privilege on the importing function but no privilege on the library itself. A SQL SECURITY DEFINER function verifies that it is executing as the low-privilege definer and then checks for the relationship row. The query returns 1: unauthorized_library_metadata_visible 1 The account should not see the relationship row because its library endpoint is not visible to that account. Revoking EXECUTE on the importing function makes the same guarded query fail with error 1772, confirming that visibility is currently authorized from the importing-function side only. How to repeat: Run as root: DROP DATABASE IF EXISTS db1; DROP USER IF EXISTS 'u1'@'%'; CREATE DATABASE db1; CREATE LIBRARY db1.lib1 LANGUAGE JAVASCRIPT AS 'export function f() { return 7; }'; CREATE FUNCTION db1.target() RETURNS INT DETERMINISTIC NO SQL LANGUAGE JAVASCRIPT USING (db1.lib1 AS lib) AS 'return lib.f();'; CREATE USER 'u1'@'%'; CREATE DEFINER='u1'@'%' FUNCTION db1.oracle1() RETURNS INT DETERMINISTIC READS SQL DATA SQL SECURITY DEFINER RETURN IF( CURRENT_USER() = 'u1@%', IF( EXISTS( SELECT 1 FROM information_schema.ROUTINE_LIBRARIES WHERE ROUTINE_SCHEMA = 'db1' AND ROUTINE_NAME = 'target' AND LIBRARY_SCHEMA = 'db1' AND LIBRARY_NAME = 'lib1' ), 1, GTID_SUBSET('not-a-gtid', '') ), GTID_SUBSET('not-a-gtid', '') ); GRANT EXECUTE ON FUNCTION db1.target TO 'u1'@'%'; GRANT EXECUTE ON FUNCTION db1.oracle1 TO 'u1'@'%'; SELECT db1.oracle1() AS unauthorized_library_metadata_visible; -- Observed: returns 1. -- Expected: error 1772, because the definer has no privilege on db1.lib1 -- and therefore should not see this relationship row. Suggested fix: Require authorization for both the importing routine and the referenced library before exposing a row through INFORMATION_SCHEMA.ROUTINE_LIBRARIES.