Skip to content

Commit 53442a1

Browse files
Continue enhancing SQL protections (#3026)
#### Rationale Robust SQL generation is important. Code cleanup and consolidation is nice too. #### Related Pull Requests - LabKey/platform#7707 #### Changes - Stored procedure and parent schema name including special characters - Test ETL to invoke the new stored procedure
1 parent 6faf59e commit 53442a1

5 files changed

Lines changed: 110 additions & 1 deletion

File tree

modules/ETLtest/module.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Name: ETLtest
2-
SchemaVersion: 26.000
2+
SchemaVersion: 26.001
33
SupportedDatabases: mssql, pgsql
44
ManageVersion: true
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<etl xmlns="http://labkey.org/etl/xml">
3+
<name>Stored Proc Special Characters</name>
4+
<description>Run a stored procedure whose schema and procedure names contain special characters (spaces, '!', and an embedded double-quote) to verify identifier quoting/escaping.</description>
5+
<transforms>
6+
<transform id="step1" type="StoredProcedure">
7+
<procedure schemaName="etl test!schema" procedureName='etl"test proc!' useTransaction="false"/>
8+
</transform>
9+
</transforms>
10+
<schedule>
11+
<poll interval="5s" />
12+
</schedule>
13+
</etl>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2026 LabKey Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
-- Create a schema and stored procedure whose names contain special characters (spaces, '!', and an embedded
18+
-- double-quote in the procedure name). These exercise the identifier quoting/escaping that SqlDialect applies
19+
-- when building the CALL statement for the DataIntegration StoredProcedureStep. The schema is registered with
20+
-- the module via the matching "etl test!schema.xml" metadata file; it is created here because the module dbscript
21+
-- filename convention only permits word-character schema names.
22+
23+
CREATE SCHEMA "etl test!schema";
24+
25+
CREATE FUNCTION "etl test!schema"."etl""test proc!"
26+
(IN transformrunid integer
27+
, INOUT rowsinserted integer DEFAULT 0
28+
, INOUT rowsdeleted integer DEFAULT 0
29+
, INOUT rowsmodified integer DEFAULT 0
30+
, INOUT returnmsg character varying DEFAULT 'default message'::character varying
31+
, OUT return_status integer)
32+
RETURNS record AS
33+
$BODY$
34+
BEGIN
35+
rowsInserted := 1;
36+
rowsDeleted := 0;
37+
rowsModified := 0;
38+
returnMsg := 'Special characters proc ran';
39+
return_status := 0;
40+
RETURN;
41+
END;
42+
$BODY$
43+
LANGUAGE plpgsql;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2026 LabKey Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
-- Create a schema and stored procedure whose names contain special characters (spaces, exclamation point, and an
18+
-- embedded double-quote in the procedure name). These exercise the identifier quoting/escaping that SqlDialect
19+
-- applies when building the CALL statement for the DataIntegration StoredProcedureStep. The schema is registered
20+
-- with the module via the matching schema metadata file; it is created here because the module dbscript filename
21+
-- convention only permits word-character schema names.
22+
23+
-- Use double-quote delimited identifiers (with the interior quote doubled as "") rather than [bracket] identifiers.
24+
-- LabKey's SqlScanner, which splits scripts into statements, does not understand bracket quoting and would misread a
25+
-- double-quote inside [ ... ] as the start of a string literal; it does correctly handle a doubled "" as an escaped
26+
-- quote inside a "-delimited identifier. QUOTED_IDENTIFIER must be ON for "..." to be treated as an identifier.
27+
SET QUOTED_IDENTIFIER ON;
28+
GO
29+
30+
CREATE SCHEMA "etl test!schema";
31+
GO
32+
33+
CREATE PROCEDURE "etl test!schema"."etl""test proc!"
34+
@transformRunId int,
35+
@rowsInserted int = 0 OUTPUT,
36+
@rowsDeleted int = 0 OUTPUT,
37+
@rowsModified int = 0 OUTPUT,
38+
@returnMsg varchar(100) = 'default message' OUTPUT
39+
AS
40+
BEGIN
41+
SET @rowsInserted = 1
42+
SET @rowsDeleted = 0
43+
SET @rowsModified = 0
44+
SET @returnMsg = 'Special characters proc ran'
45+
RETURN 0
46+
END
47+
GO
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Registers the special-character schema "etl test!schema" with the ETLtest module so the DataIntegration
3+
StoredProcedureStep can resolve it. The schema holds only a stored procedure (no tables); it is
4+
created by the etltest-26.000-26.001.sql dbscript. -->
5+
<tables xmlns="http://labkey.org/data/xml">
6+
</tables>

0 commit comments

Comments
 (0)